这是我的密码..。
male = "male"
female = "female"
role = input("Are you a male or female? ")
if role == male:
print("male")
if role == female:
print("female")结果:你是男性还是女性?男的是男的还是女的?女性女性你是男性还是女性?nale (没有任何退货)
*如果您在输入响应中拼错了一个单词,您的代码是否有其他方法打印?
我试着添加新的tried语句,一个新的“错误”变量,然后添加一个elif语句。
例:
male = "male"
female = "female"
typo = not "cat" or "dog"
role = input("Are you a male or female? ")
if role == male:
print("male")
elif typo:
print("over")
if role == female:
print("female")
elif typo:
print("over")结果:你是男性还是女性?你是男的还是女的?女性多于女性你是男性还是女性?转过去
发布于 2020-02-13 19:06:09
如果我理解你的问题正确的话,你可以这样做:
your_input = 'male'
valid_inputs = ['cat', 'dog']
if your_input in valid_inputs:
print(your_input)
else:
print('over')https://stackoverflow.com/questions/60214392
复制相似问题