#coding=utf-8 #!/usr/local/bin/python3 import random import sys keyNumber = random.randint(1, 20)#生成1~20的随机数 decodeNumber = 0 flag = "N" while decodeNumber != keyNumber: print("请输入您猜的数:") try: decodeNumber = int(input()) except ValueError: print("您见过这样的数字吗?") print("亲,请再输一次!") continue if decodeNumber > keyNumber: print("输入的数字大了些,再试一次!") elif decodeNumber < keyNumber: print("输入的数字小了些,再试一次!") else: print("哇,您猜对了,您可以去买彩票了!") print("还要再玩一次吗?(y/n)") flag = input() if flag != "y": print("亲,慢走,欢迎下次再来!") sys.exit() else: keyNumber = random.randint(1, 20)
原文地址:http://dearleo.blog.51cto.com/6718690/1631404