我正在介绍使用Python进行计算机编程的介绍,因此我很陌生。我正在尝试制作食谱计算器,但是每当我尝试运行该程序时,它都会说语法无效,然后在第27行(在#Display Recipe下)突出显示更新1。
#Let the user input the name of the recipe
recipe = str(input("Enter the name of your recipe"))
#Let the user input ingredients and their amounts
ingredient1 = input(str("Please enter ingredient 1"))
ing1amount = input(float("Please enter amount of ingredient 1"))
ingredient2 = input(str("Please enter ingredient 2"))
ing2amount = input(float("Please enter amount of ingredient 2"))
ingredient3 = input(str("Please enter ingredient 3"))
ing3amount = input(float("Please enter amount of ingredient 3"))
ingredient4 = input(str("Please enter ingredient 4"))
ing4amount = input(float("Please enter amount of ingredient 4"))
ingredient5 = input(str("Please enter ingredient 5"))
ing5amount = input(str("Please enter amount of ingredient 5"))
#Let user input number of people to feed
people = int(input("How many people would you like to feed?"))
#calculate amount of ingredients based on people fed
newing1 = ing1amount * people
newing2 = ing2amount * people
newing3 = ing3amount * people
newing4 = ing4amount * people
newing5 = ing5amount * people
#Display Recipe
print("For your recipe, you will need" newing1 "cups of" ingredient1)
print("For your recipe, you will need" newing2 "cups of" ingredient2)
print("For your recipe, you will need" newing3 "cups of" ingredient3)
print("For your recipe, you will need" newing4 "cups of" ingredient4)
print("For your recipe, you will need" newing5 "cups of" ingredient5)
任何帮助将不胜感激!
答案 0 :(得分:1)
使用,
逗号的最佳方法,因为它们之间有空格,并且不需要类型转换:
print("For your recipe, you will need", newing1 ,"cups of" ingredient1)
print("For your recipe, you will need", newing2 ,"cups of" ingredient2)
print("For your recipe, you will need", newing3 ,"cups of" ingredient3)
print("For your recipe, you will need", newing4 ,"cups of" ingredient4)
print("For your recipe, you will need", newing5 ,"cups of" ingredient5)