当用户没有输入正确的字符时,我试图得到消息“无效值”,但程序重新启动而不打印消息。你可以帮我吗?
# Print "Male" when the user types "M" and "Female" when the user types "F"
def m_ou_f():
mens_erro = "INVALID VALUE"
while True:
try:
sex = str(input("Type M for Male or F for Female: "))
sex == "M" or sex == "F" or sex == "f" or sex == "m"
except:
print(mens_erro)
continue
else:
return sex
break
while True:
sex = m_ou_f()
try:
sex == "M" or sex == "F" or sex == "f" or sex == "m"
except:
print("INVALID VALUE!")
continue
else:
if sex == 'M' or sex == 'm':
print("Male")
break
elif sex == 'F' or sex == 'f':
print("Female")
break
神不在的星期二
红颜莎娜
相关分类