所以我在这段本应模拟掷骰子模拟器的代码中遇到了一些问题,但无论我怎么尝试,我都无法再次跳出while循环。
import random
print('-------------------------------------------------------')
print(' WELCOME TO THE DICE ROLLING SIMULATOR')
print('-------------------------------------------------------')
while True:
randomNumber = str(random.randint(1, 6))
rollAgain = input('would you like to roll the dice? yes or no?')
if rollAgain == 'yes' or ' yes':
print('Rolling the dice')
print('the dice landed on the number: ' + randomNumber)
elif rollAgain == 'no' or ' no':
quit()
发布于 2019-01-07 05:03:42
每次都需要根据值检查变量。在队伍中
if rollAgain == 'yes' or ' yes':
Python每次都会将' yes'
计算为true
。您还需要将其与rollAgain
进行比较。
下面是固定的代码:
import random
print('-------------------------------------------------------')
print(' WELCOME TO THE DICE ROLLING SIMULATOR')
print('-------------------------------------------------------')
while True:
randomNumber = str(random.randint(1, 6))
rollAgain = input('would you like to roll the dice? yes or no?')
if rollAgain == 'yes' or rollAgain == ' yes':
print('Rolling the dice')
print('the dice landed on the number: ' + randomNumber)
elif rollAgain == 'no' or rollAgain == ' no':
quit()
https://stackoverflow.com/questions/54065887
复制相似问题