forked from INM-6/Python-Module-of-the-Week
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.py
58 lines (48 loc) · 1.36 KB
/
Generator.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from random import randint, choice
Pizza_Ingredients = [
'tomatoes',
'flour',
'water',
'yeast',
'mozzarella',
'pineapple',
'paella',
'mushrooms',
'spinach (frozen)',
'kiwi',
'mashed potatoes',
'banana'
]
stuff_i_do_not_like = [
'water',
'flour'
]
def safe_food(ingredients, leave_out):
for ingredient in ingredients:
if ingredient not in leave_out:
yield ingredient
def adapted_recipe(ingredients, leave_out):
units = ['stone', 'yard', 'torr^2/horsepower', 'morgen', 'handful', 'metric decipound']
for ingredient in safe_food(ingredients, leave_out):
yield f"{randint(1, 5)} {choice(units)} {ingredient}"
"""
for item in adapted_recipe(
ingredients=Pizza_Ingredients,
leave_out=stuff_i_do_not_like,
):
print(item)
"""
def adapted_recipe_hungry(ingredients, leave_out):
units = ['stone', 'yard', 'torr^2/horsepower', 'morgen', 'handful', 'metric decipound']
hunger = 0
for ingredient in safe_food(ingredients, leave_out):
hunger = yield f"{randint(1, 5) + hunger} {choice(units)} {ingredient}"
recipe_generator = adapted_recipe_hungry(
Pizza_Ingredients,
stuff_i_do_not_like)
recipe_generator.send(None)
for hunger in range(len(Pizza_Ingredients)):
try:
print(recipe_generator.send(hunger))
except(StopIteration):
break