猜数字游戏
#-*- coding:utf-8
import random
guessesTaken = 0
print('Hello! 请问你叫什么名字?')
myName = input('输入你的名字:')
number = random.randint(1,20)
print(myName+ ',我想的是1到20之间的数字.')
while guessesTaken <6:
print('请输入你的数字:')
guess = input()
try:
guess = int(guess)
guessesTaken = guessesTaken + 1
except:
print('你输入错误,请从新输入:')
continue
if guess < number:
print('你输入的数字太低了')
if guess > number:
print('你输入的数字太高了')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print('太棒了, ' + myName + '! 你猜了' + guessesTaken + '次我的数字')
if guess != number:
number = str(number)
guessesTaken = str(guessesTaken)
print('我对你太失望了,猜了'+guessesTaken+'次都没猜对。我想的数字是'+number+'!!!')
posted on 2018-08-07 11:46 Test-Admin 阅读(394) 评论(0) 编辑 收藏 举报