Difference between revisions of "Guessing Game Assignment"

From WLCS
Line 8: Line 8:
 
'''Guessing Game Algorithm'''
 
'''Guessing Game Algorithm'''
 
# Generate a random number from 0 to 100
 
# Generate a random number from 0 to 100
 +
 
<source lang="python">
 
<source lang="python">
 
import random (at the very top)
 
import random (at the very top)
Line 13: Line 14:
 
</source>
 
</source>
  
#
+
# Prompt the user to guess a number
 +
# If the guessed number is higher than the random number, then print "Guess lower"
 +
# If the guessed number is lower than the random number, then print "Guess higher"
 +
# If the guessed number is equal to the random number, then print "you win!" and exit loop
 +
# Repeat steps 2 - 5 with loop (while the guessed number does not equal the random number)

Revision as of 14:14, 24 October 2008

Guessing Game Rules

  1. Mr. Bui will think of a number from 0 to 100
  2. You will guess a number
  3. Mr. Bui will tell you to guess higher or lower
  4. You will guess again, and so on and so forth.


Guessing Game Algorithm

  1. Generate a random number from 0 to 100
import random (at the very top)
randomNum = random.randint(0, 100)
  1. Prompt the user to guess a number
  2. If the guessed number is higher than the random number, then print "Guess lower"
  3. If the guessed number is lower than the random number, then print "Guess higher"
  4. If the guessed number is equal to the random number, then print "you win!" and exit loop
  5. Repeat steps 2 - 5 with loop (while the guessed number does not equal the random number)