-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex19sd3.py
More file actions
34 lines (27 loc) · 1.44 KB
/
ex19sd3.py
File metadata and controls
34 lines (27 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Exercise 19: Functions and Variables
# http://learnpythonthehardway.org/book/ex19.html
# Study Drill 3: Write at least one more function of your own design, and run it 10 different ways.
def milkshake(milk_to_blend, fruit_to_blend, suggar_to_blend):
"""
Calculates serving size and prints out ingredient amounts
for milkshake.
"""
servings = int(raw_input("Oh yeah, I forgot! For how many servings shall all this be? "))
milk_to_serve = servings * milk_to_blend
fruit_to_serve = servings * fruit_to_blend
suggar_to_serve = servings * suggar_to_blend
print "You'll need %d g fruit, %d mL milk and %d g of suggar. Will it blend?!" % (fruit_to_serve, milk_to_serve, suggar_to_serve)
milk = 200
fruit = 50
suggar = 10
print "\nLet's make a milkshake! I know this recipe: Blend %d mL milk, %d g fruit and %d g suggar in a blender. However, you should adjust something..." % (milk, fruit, suggar)
# get recipe modifiers from user; can be negative
fruitiness = float(raw_input("... Like the fruitiness! How many % more or less do you want? "))
sweetness = float(raw_input("Same for the sweetness: "))
print "\n\nResults calculated in function call:"
milkshake(milk, fruit * (1 + (fruitiness / 100)), suggar * (1 + (sweetness / 100)))
print "\n\nResults calculated via helper variables:"
milk_to_blend = milk
fruit_to_blend = fruit * (1 + (fruitiness / 100))
suggar_to_blend = suggar * (1 + (sweetness / 100))
milkshake(milk_to_blend, fruit_to_blend, suggar_to_blend)