给定一个1-99之间的数,让用户猜数字,当用户猜错时会提示用户猜的数字是过大还是过小,知道用户猜对数字为止,猜对数字用的次数越少成绩越好。
import random n = random.randint(1, 99) guess = int(raw_input("Enter an integer from 1 to 99: ")) while n != "guess": print if guess < n: print "guess is low" guess = int(raw_input("Enter an integer from 1 to 99: ")) elif guess > n: print "guess is high" guess = int(raw_input("Enter an integer from 1 to 99: ")) else: print "you guessed it!" break print