【发布时间】:2021-02-28 03:10:00
【问题描述】:
我找不到错误。我将非常感谢一些帮助!提前谢谢你。
""" 该程序要求用户提供三种成分, 三份量和份数,以及 确定每种成分需要多少 送达指定份数。 """
ingredient_one = input("What is the first ingredient?: ")
ing_one_oz = int(input("How many ounces of this ingredient?: ")
ingredient_two = input("What is the second ingredient?: ")
ing_two_oz = int(input("How many ounces of this ingredient?: ")
ingredient_three = input("What is the third ingredient?: ")
ing_three_oz = int(input("How many ounces of this ingredient?: ")
servings_amt = int(input("How many servings would you like?: ")
ing_one_oz = ing_one_oz * servings_amt
ing_two_oz = ing_two_oz * servings_amt
ing_three_oz = ing_three_oz * servings_amt
print("In order to make " + str(servings_amt) + " servings of your recipe, you will need " + str(ing_one_oz) + " ounces of " /
+ str(ingredient_one) + ", " + str(ing_two_oz) + " ounces of " + str(ingredient_two) + ", and " + str(ing_three_oz) /
+ " ounces of " + str(ingredient_three) + ".")
输出在第 3 行显示语法错误,该错误以变量成分_two 开头。 第 1 行已经通过“正确”,但第 3 行没有,尽管它们实际上是相同的。
【问题讨论】:
-
您的多行括号不匹配,例如
int(input("How many ounces of this ingredient?: ")缺少右括号。另外,考虑使用f-strings 进行字符串格式化。 -
您的错误是拼写错误。你在很多地方都错过了第二个
)。我建议你使用像 PyCharm 这样的 IDE 来捕捉这些。
标签: python variables input syntax-error