-1

I could not find the error in the last line. I am a complete beginner to this language. Thanks in advance.

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))

My output said TypeError: bad operand type for unary +: 'str' for the last line.

  • You used the wrong symbol (virgule a.k.a slash) for line continuation. The correct symbol is the antivirgule (back-slash). – Prune Feb 28 '21 at 04:50
  • The slashes instead of backslashes. Which are BTW not needed inside of parentheses. – Klaus D. Feb 28 '21 at 04:51
  • Does this answer your question? [Concatenate strings in python in multiline](https://stackoverflow.com/questions/34295901/concatenate-strings-in-python-in-multiline) – Gino Mempin Feb 28 '21 at 13:04

1 Answers1

2

You can't use backslashes when performing operations with strings. I believe this will solve your problem.

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(
    f"In order to make {servings_amt} servings of your recipe, you will need {ing_one_oz} ounces of {ingredient_one}, {ing_two_oz} ounces of {ingredient_two}, {ing_three_oz} ounces of {ingredient_three}")
Dhruv Jadhav
  • 260
  • 1
  • 11