Py学习  »  Python

用PythonCharm编写一个猜年龄的小游戏!

Python面试官 • 5 月前 • 142 次点击  


import random #把random模块调用出来age = random.randint(10,25)#用rand.randint制造一个随机数表count = 0while count 3:#共有三次机会    n = int(input('Guess the age:'))#输入用户通过键盘敲打的数据if n > age:        print('Try smaller,你还有%s次机会'%(2-count))        count += 1elif n < age:        print('Try bigger,你还有%s次机会'%(2 - count))        count += 1else:        print('Yes,you get it')break#结束循环print(age)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/185624