【发布时间】:2022-11-14 09:11:49
【问题描述】:
我是一名中学生,我开始学习 python 编码。我一直在看视频教程,但如果你输入 q,我似乎无法弄清楚如何让游戏退出。这里我有什么..
print('How old do you thing Fred the Chicken is?')
number = 17
Quit = q
run = 17
while run:
guess = int(input('Enter What You Think His Age Is....'))
print('How old do you thing Fred the Chicken is?')
number = 17
Quit = 'q'
run = 17
while run:
guess = int(input('Enter What You Think His Age Is....'))
if guess == number:
print('Yes :D That is his age...')
run = False
elif guess < number:
print('No, Guess a little higher...')
elif guess > number:
print('No, Guess a little lower....')
print('Game Over')
print('Press Q to Quit')
if run == False:
choice = input('Press Q to Quit')
if choice == 'q'
import sys
exit(0)
【问题讨论】:
-
如果您愿意,您可以使用
number = random.randint(0,10),这样它就不会总是每场比赛都设置为 17。请记住在文件顶部添加import random。阅读更多here
标签: python string python-3.x quit