Hotter/Colder Number Game in Python -
i'm working way through code academy python course , have been trying build small side projects reinforce lessons.
i'm working on number game. want program select random number between 1 , 10 , user input guess.
then program return message saying win or prompt pick higher/lower number.
my code listed below. can't reiterate process second user input.
i don't want answer, hint.
import random random.seed() print "play number game!" x = raw_input("enter whole number between 1 , 10:") y = random.randrange(1, 10, 1) #add loop in here make game repeat until correct guess? if x == y: print "you win." print "your number ", x, " , number ", y elif x > y: x = raw_input("your number high, pick lower one: ") elif x < y: x = raw_input("your number low, pick higher one: ")
you need use while
loop while x != y:
. here more info while loop.
, can use
import random y = random.randint(1, 10)
instead other random
function.
and think should learn int()
function at here.
these hints :)
import random n = random.randint(1, 10) g = int(raw_input("enter whole number between 1 , 10: ")) while g != n: if g > n: g = int(raw_input("your number high, pick lower one: ")) elif g < n: g = int(raw_input("your number low, pick higher one: ")) else: print "you win." print "your number ", g, " , number ", n
Comments
Post a Comment