logo
Published on Models of Motion (http://www2.evergreen.edu/modelsofmotion)

CS Lab Week 4

1.  Read Code:

a=5
b=1
while a>b:
    print"again",b
    if b==3:
        print"more",a
        while a>b:
            print"loop",b
            b=b+1
            a=4
        b=2
    b=b+2
    print"another",b
    if a==4:
        print"after",a
        a=5
print "loop again"

2.  Write Code:  
       Write a program to get values from the user until the user enters a 0.  For each number tell if it is odd or even.  If it is over 90, tell the user "good job"  When the loop is exited, print the highest odd score, the average of all the even numbers, and the number of odd scores.

3.  Graphics:  Play

4.  Functions:   Pseudocode: number guess game

from random import randrange

def getNumber():
    return randrange(1,100)

def getGuess():
    guess = input("enter your guess")
    return guess

def TooLow():
    print"too low"

def TooHigh():
    print"too high"

def countGuesses(count):
    return count+1

def RightOn():
    print"Right you are!"

def Howmanyguesses():
    print "it took you", count,"guesses"

count=0
guess = getGuess()
num = getNumber()
print num
while guess!=num:
    if guess>num:
        TooHigh()
    if guess<num:
        TooLow()
    count=countGuesses(count)
    guess=getGuess()

RightOn()
Howmanyguesses()

5.  Craps

Visual Python:

1.  Graphics Package, Zelle

2.  Projectile: Hit it..


Source URL:
http://www2.evergreen.edu/modelsofmotion/modelsofmotion/cs-lab-week-4