
Ethan S. answered 03/31/20
Ivy League Computer Science and Math Tutor

Ethan S.
You're welcome! It's tricky learning Python, so if there's anything else I can help with just let me know :)03/31/20
Ui-Jeen Y.
asked 03/31/20The assignment's output should be something like this:
The following is an order for a plain pizza, a ham and anchovy pizza, two "tub"-sized drinks, with a 10%-off coupon:
I am given the prices for all the items and I should be able to calculate the cost of an order with one function. However, I cannot figure out how to count each of the elements in drinks (for example) and apply the separate prices of the different sizes (small, medium, large, tub).
I made a dictionary:
drinks = {"small":2, "medium": 3, "large": 3.5, "tub":3.75}
But I do not know how to use this to access the prices for each element of drinks (ex. drinks = ["tub", "tub"] would be priced as $7.50).
I tried to do:
for your_drinks in drinks:
your_drinks = drinks.count("small")*2 + drinks.count("medium")*4 + drinks.count("large")*3.5 + drinks.count("tub") * 3.75
return x
But this gives me $3.75, but the answer should be $7.50 for two small drinks (I have no idea why). I hard coded the prices because I did not know how to use the dictionaries logically. I am a beginner in python and I am not very knowledgeable about lists/dictionaries.
Ethan S. answered 03/31/20
Ivy League Computer Science and Math Tutor
Ethan S.
You're welcome! It's tricky learning Python, so if there's anything else I can help with just let me know :)03/31/20
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Ui-Jeen Y.
Thank you so much! I think I just need to be more knowledgeable about that difference.03/31/20