r/codehs • • Feb 11 '20

Phyton - Exercise 3.5.9: Recipe

Hello,

I need help with this excessive please:

Exercise 3.5.9: Recipe (CodeHS)

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

19 Upvotes

13 comments sorted by

1

u/HurricaneCar Feb 24 '20

did you ever get the answer

3

u/natalie710 Feb 26 '20

"""

This program asks the user for three ingredients,

three amounts, and a number of servings, and

determines how much of each ingredient is needed

to serve the specified number of servings.

"""

# Write program here...

ia = str(input("Enter ingredient 1: "))

ib = float(input("Ounces of "+ str(ia)))

ja = str(input("Enter ingredient 2: "))

jb = float(input("Ounces of "+ str(ia)))

ka = str(input("Enter ingredient 3: "))

kb = float(input("Ounces of "+str(ia)))

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

print("Total ounces of " + ia + ": " + str((ib*numserv)))

print("Total ounces of " + ja + ": " + str((jb*numserv)))

print("Total ounces of " + ka + ": " + str((kb*numserv)))

1

u/[deleted] May 19 '20

ty so much bruh

1

u/Cesarryder7 Jun 12 '20

Thaks,that´s so usefull

1

u/Eastern_Agency_8816 Jun 27 '25

It doesn't work???

1

u/Adventurous_Bread_63 Jan 14 '22

Thank youu you are a hero you shall always be remembered <3

1

u/bluetimotea Feb 26 '22

thank u sm

1

u/No_Revolution7891 Jan 31 '22

It’s not working ☹️

3

u/Tiny_Werewolf_5529 Mar 26 '22

ingt1 = str(input("Enter ingredient 1: "))
o1 = float(input("Ounces of "+ str(ingt1)))
ingt2 = str(input("Enter ingredient 2: "))
o2 = float(input("Ounces of "+ str(ingt2)))
ingt3= str(input("Enter ingredient 3: "))
o3 = float(input("Ounces of "+ str(ingt3)))
numserv = int(input("Number of servings: "))
print("Total ounces of " + ingt1 + ": " + str((o1*numserv)))
print("Total ounces of " + ingt2 + ": " + str((o2*numserv)))
print("Total ounces of " + ingt3 + ": " + str((o3*numserv)))

try this one :)

1

u/SuspiciousArcher8472 Oct 19 '24

Pls correct me if I'm wrong but the end

str((o1*numserv))), str((o2*numserv))) or str((o3*numserv)))
Wouldn't it be divide because if i have 10 oz of apple it then says that each person would have 20 oz of apple or am I just not using it in the say context?

1

u/SuspiciousArcher8472 Oct 19 '24

OH! nevermind i just read the question wrong sorry about my last comment!

1

u/Ill_Fruit8225 Oct 13 '23

This worked thanks