|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下:
- import random
- #获取计算机的随机数
- computer = random.randint(0,30)
- active = True
- while active:
- """定义计算器,并递减输出"""
- for count in range(6,0, -1):
- print("当前剩余猜测次数{0}".format(count))
- guess = int(input("请输入1-30的整数 :"))
- """对比guess和computer大小,如果相等,则退出游戏"""
- if guess < computer:
- print("Sorry,guess more than computer smaller!")
- elif guess > computer:
- print("Sorry,guess more than computer bigger")
- else:
- print("Congratulations, answer correctly.answer is {0}".format(computer))
- active = False
- break
- """次数用尽,询问用户是否继续游戏"""
- answer = input("The number of guesses has been used up,whether to continue[yes or no] :")
- if answer == "yes":
- continue
- else:
- print("Thanks for participating in the game, goodbye.")
- break
复制代码
求问各位大佬,如何实现当guess = computer的时候立即终止游戏。感谢各位大佬
|
|