python学习:猜数字游戏
猜数字游戏
系统生成一个100以内的随机整数,
玩家有6次机会进行猜猜看,每次猜测都有反馈(猜大了,猜小了,猜对了-结束)
6次中,猜对了,玩家赢了。
否则系统赢了
#!/usr/bin/env python
import random
secret=random.randint(1,100)
guess=0
tries=0
print "This game is to guess a number for you!"
print " It is a number from 1 to 99,I'll give you 6 times to try. "
while guess != secret and tries < 6:
guess=input("Please input your guess number: ")
if guess < secret:
print "====Your guess is too low !====\n"
elif guess > secret:
print "====Your guess is too high!====\n"
tries=tries+1
if guess == secret:
print "Congratulations to you! Your guess is right ! "
else:
print "No more guesses! Good luck next time for you!"
print "The secret number was",secret