Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

10 points status: not submitted write a program that asks the user for …

Question

10 points status: not submitted
write a program that asks the user for the following things:

  • the names of three ingredients for a salad recipe.
  • the number of ounces of each ingredient required for one - serving (these should just be floats, like 2.5). make sufe to handle the users input correctly by converting it to a float as you capture it.
  • the number of servings desired (this should be an integer). you should only ask for the number of servings once. make sure to handle the users input correctly by converting it to an int as you capture it.

the program should then output the total number of ounces of each ingredient required to make the desired number of servings.
an example run of your program might look like this:
enter ingredient 1: mixed greens
ounces of mixed greens: 1.7
enter ingredient 2: blueberries
ounces of blueberries: 2.0
enter ingredient 3: walnuts
ounces of walnuts: 0.2
number of servings: 3
total ounces of mixed greens: 5.1
total ounces of blueberries: 6.0
total ounces of walnuts: 0.6
note: you must ask the user for an ingredient, and then the amount of that ingredient (as shown in the example above) in order to pass the autograder.

Explanation:

Step1: Get ingredient names

Use input() function to prompt user for ingredient names one - by - one.

ingredient1 = input("Enter ingredient 1: ")
ingredient2 = input("Enter ingredient 2: ")
ingredient3 = input("Enter ingredient 3: ")

Step2: Get ounces per serving

Use input() and convert to float for each ingredient's ounces per serving.

ounces1 = float(input(f"Ounces of {ingredient1}: "))
ounces2 = float(input(f"Ounces of {ingredient2}: "))
ounces3 = float(input(f"Ounces of {ingredient3}: "))

Step3: Get number of servings

Use input() and convert to int for number of servings.

servings = int(input("Number of servings: "))

Step4: Calculate total ounces

Multiply ounces per serving by number of servings for each ingredient.

total_ounces1 = ounces1 * servings
total_ounces2 = ounces2 * servings
total_ounces3 = ounces3 * servings

Step5: Output results

Print out the total ounces for each ingredient.

print(f"Total ounces of {ingredient1}: {total_ounces1}")
print(f"Total ounces of {ingredient2}: {total_ounces2}")
print(f"Total ounces of {ingredient3}: {total_ounces3}")

Answer:

The above Python code is the solution.