【发布时间】:2022-11-03 07:49:49
【问题描述】:
所以 if 和 elif 语句不起作用
def weight_converter():
print("Welcome to Weight Converter")
operation = int(input(" 1. Gram to Pound \n 2. Pound into Gram"))
if operation == " 1":
gram_one = int(input("Grams needed to convert to pound: "))
print("You have", gram_one * 453.57,"pounds")
elif operation == " 2":
pound_one = int(inpu())
weight_converter()
所以我期待 if 语句运行,但是 gram_one 输入没有出现。请帮我解决这个问题。
【问题讨论】:
-
operation=int(whatever)表示运算是整数。所以它不可能是字符串" 1"。'operation == " 1"和"operation == " 2"不可能是真的 -
尝试
if operation == 1而不是if operation == " 1"。另外,inpu()是什么?这看起来像一个错字。 -
以下任何答案是否对您有用或帮助您解决问题?请mark it as accepted 和give it an upvote。它将允许社区中面临相同问题的其他人更轻松地找到他们的答案。
标签: python