求助大佬
本帖最后由 英俊男孩建坤 于 2021-1-10 00:49 编辑f_or_c = input("Please enter selection(F or C): ")
if f_or_c != "F" and f_or_c != "C":
while True:
f_or_c = input("Please enter selection again: ")
if f_or_c == "F" and f_or_c == "C":
break
我应该怎么修改才能在输入错误的选择后再次输入正确的选择时跳出循环(要求用while True的形式) f_or_c = input("Please enter selection(F or C): ")
while True:
if f_or_c != "F" and f_or_c != "C": #不是F,也不是C时,重新输入
f_or_c = input("Please enter selection again: ")
elif f_or_c == "F" or f_or_c == "C": #是F或者C时,跳出即可
break
测试:
Please enter selection(F or C): k
Please enter selection again: g
Please enter selection again: F
Please enter selection(F or C): k
Please enter selection again: J
Please enter selection again: C
如果回答满意,请设为最佳答案
页:
[1]