Random numbers in Python
To create random numbers in python there are two steps.
import random |
Submit your answer here |
This program will print random numbers between 0 and 99 on the screen over and over again.
Number guessing challenge
Make the program 'think of a number'
Create a variable called myNumber and assign a random number between 0 and 99
Create a variable called correctGuess and assign its value as false
Create a variable called myGuess and assign its value as 0
Loop for as long as correctGuess is false
prompt the user to enter a number
use int(raw_input()) to read the number into the variable myGuess
if myGuess is equal to myNumber, then the user has won. Say "Well Done" and set correctGuess to true
if myGuess is less than myNumber, then say "Too Low"
if myGuess is greater than myNumber, then say "Too High"
Create a variable called myNumber and assign a random number between 0 and 99
Create a variable called correctGuess and assign its value as false
Create a variable called myGuess and assign its value as 0
Loop for as long as correctGuess is false
prompt the user to enter a number
use int(raw_input()) to read the number into the variable myGuess
if myGuess is equal to myNumber, then the user has won. Say "Well Done" and set correctGuess to true
if myGuess is less than myNumber, then say "Too Low"
if myGuess is greater than myNumber, then say "Too High"
What is the maximum number of guesses that you should need to be able to find any number between 0 and 99?
Can you make the program keep a score - if the player goes above the maximum number, the computer should declare victory and show the number it was thinking of.
Can you make the program keep a score - if the player goes above the maximum number, the computer should declare victory and show the number it was thinking of.