我不断得到
TypeError: addIngredients() missing 1 required positional argument: 'ingredientQuantity'
但是,当我运行代码时,我已经按照正确的顺序传递了正确数量的位置参数。谁能指出我哪里出了问题?它使我发疯。
这在食谱类中,并且在主程序中被调用。
def addIngredients(self, ingredientName, ingredientSize, ingredientUnitOfMeasure, ingredientQuantity):
"""Add ingredients to the recipe"""
self.ingredientName = ingredientName
self.ingredientSize = ingredientSize
self.ingredientUnitOfMeasure = ingredientUnitOfMeasure
self.ingredientQuantity = ingredientQuantity
recipeFile = open("Recipes.txt", "a")
recipeFile.write("\n" + ingredientName + " " + ingredientSize + " " + ingredientUnitOfMeasure + " " + ingredientQuantity +
". \nEnd of recipe")
我的问题发生在
ingredient = Recipe.Recipe.addIngredients(ingredientName, ingredientSize, ingredientUnitOfMeasure, ingredientQuantity)
while on:
menuSelection = int(input("Would you like to: \n1. Create a recipe\n2. View a recipe\n3. Update a recipe\n4. Delete a recipe\n5. Quit"))
while menuSelection != 1 or 2 or 3 or 4 or 5:
if menuSelection == 5:
on = False
elif menuSelection == 1:
recipeName = input("Please type in the name of the recipe: ")
recipeName = Recipe.Recipe('\n' + recipeName)
addIngredient = True
while addIngredient:
ingredientName = input("Please enter the name of your first ingredient: ")
ingredientSize = input("Please enter the size of the ingredient: ")
ingredientUnitOfMeasure = input("Please enter the unit of measurement. Grams, millilitres etc:")
ingredientQuantity = input("Please enter the quantity of the ingredient:")
ingredient = ''
ingredient = Recipe.Recipe.addIngredients(ingredientName, ingredientSize, ingredientUnitOfMeasure, ingredientQuantity)
continueAdding = True
answer = input("Would you like to add another ingredient? Type yes or no.\n")
while continueAdding:
if answer.lower() == 'y' or 'yes':
addIngredient = True
break
elif answer.lower() == 'n' or 'no':
addIngredient = False
break
else:
answer = input("Please type yes or no.")
print("You have finished adding all of your ingredients.\n")
print("You have added " + recipeName + " to the recipe database.")
我们非常感谢您的帮助。