实施例
Good=1
Bad=2
print("How was your day?")
input()
if Good:
Print("That's nice.")
elif Bad:
Print("That's unfortunate")
出于某种原因,这个程序总是以“那很好”的方式回应。即使我说不好。
答案 0 :(得分:1)
if Good
始终为True
,您必须为变量分配输入然后进行比较:
inp = input()
if inp == Good:
...
答案 1 :(得分:0)
您获取了输入值,但没有将其分配给变量。
你应该引入一个新变量(我们称之为answer
):
good=1
bad=2
print("How was your day?")
answer = input() ## <-- changed
if answer == good: ## <-- changed
print("That's nice.")
elif answer == bad: ## <-- changed
print("That's unfortunate")
答案 2 :(得分:0)
您没有将输入值分配给变量。请尝试以下代码:
Good = 1
Bad = 2
print('How was your day?')
inputVal = int(input())
if inputVal == Good:
print("That's nice.")
elif inputVal == Bad:
print("That's unfortunate")
输入:1个
输出:那很好。
输入:2
输出:那是不幸的