我正在尝试制作一个命运之轮游戏,并试图让这两个代码同时运行 第一个while循环是检查它是元音还是辅音,第二个while循环是检查之前是否已经拾取了辅音
if currentguess in vowels:
consonantcheck = False
while consonantcheck == False:
currentguess = input('Not a consonant, please try again with a consonant: ')
if currentguess not in vowels:
consonantcheck = True
if currentguess in addedcons:
consalreadyadded = False
while consalreadyadded == False:
currentguess = input('The consonant is already guessed, pick another consonant: ')
if currentguess not in addedcons:
consalreadyadded = True
与两个循环都依赖于各自作用域内确定的条件不同,您可以有一个循环在满足条件时中断
为了对同一输入进行两次验证检查,仅当输入通过所有验证时,才可以在不确定的
while
循环和break
中使用if
和elif
语句:演示:https://repl.it/@blhsing/UnwrittenSpanishInteger
相关问题 更多 >
编程相关推荐