这是代码。我想写一个不同的短语,该短语需要根据Q1响应进行打印,但是该程序无法正常工作,并会打印所有短语。
print ('Pet animals')
#choose an animal
print ('A. Dog')
print ('B. Cat')
print ('C. Hamster')
print ('D. Bird')
print ('E. None')
Q1response= input('I have a ')
if(Q1response == "A" or "a"):
print ('They are so cute')
elif (Q1response == "B" or "b"):
print ('They are so haughty')
答案 0 :(得分:0)
if条件始终返回true
。它们应该看起来像:
if(Q1response == "A" or Q1response == "a"):
您可以将输入转换为小写以使其更容易:
Q1response=input('I have a ').strip().lower()
if(Q1response == "a"):
print ('They are so cute')
elif (Q1response == "b"):
print ('They are so haughty')