x = True
y = False
i = input("How many nose you have : ")
ans = 1
if i == 1:
print(x)
elif i == 2:
print(y)
print(ans)如果输入为2,则应该打印y的值。但是,它没有打印此输入的y值。我不知道如何解决这个问题。
发布于 2022-01-02 05:35:24
input()返回一个字符串。你应该使用:
i = int(input("How many nose you have : "))若要将输入转换为整数,请执行以下操作。
发布于 2022-01-02 05:39:07
重要的是python输入()获取字符串中的所有内容,要在其他数据类型中使用它,就必须在字符串中键入或比较。
x = True
y = False
i = input("How many nose you have : ")
ans = 1
if int(i)==1:
print(x)
elif int(i)==2:
print(y)
print(ans)发布于 2022-01-02 06:13:47
x = True
y = True
i = int(input("How many nose you have: "))
ans = 1
if i == 1:
print(x)
elif i == 2:
print(y)
print(ans)虽然我不建议这样做,因为你仍然可以做3和其他数字。我建议你这样做:
a = int(input("How many nose do you have?: "))
ans = 1
if a == ans:
print(True)
else:
print(False)
print("The answer is " + ans + "!")https://stackoverflow.com/questions/70553822
复制相似问题