我的if,elif,else语句总是产生else,即使if为真。
value = input("Please enter a product code.")
if value == 34512340:
#code
elif value == 98981236:
#code
else:
print("Product not found")
当我输入34512340时,我得到"未找到产品"
答案 0 :(得分:0)
Python始终将input()
视为字符串,因此将input()
强制转换为int:
value = int(input("Please enter a product code."))
if value == 34512340:
#code
elif value == 98981236:
#code
else:
print("Product not found")