-
Notifications
You must be signed in to change notification settings - Fork 0
/
pizzas.py
56 lines (46 loc) · 1.55 KB
/
pizzas.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
import json
from json import JSONEncoder
import random
class Pizza:
def __init__(self, cheese, meats, veggies):
self.cheese = cheese
self.meats = meats
self.veggies = veggies
class PizzaEncoder(JSONEncoder):
def default(self, o):
return o.__dict__
def calc_cheese():
i = random.randint(0, 6)
cheeses = ['extra', 'none', 'three cheese', 'goat cheese', 'extra', 'three cheese', 'goat cheese']
return cheeses[i]
def calc_meats():
i = random.randint(0, 4)
meats = ['pepperoni', 'sausage', 'ham', 'anchovies', 'salami', 'bacon', 'pepperoni', 'sausage', 'ham', 'anchovies', 'salami', 'bacon']
selection = []
if i == 0:
return 'none'
else:
for n in range(i):
selection.append(meats[random.randint(0, 11)])
return ' & '.join(set(selection))
def calc_veggies():
i = random.randint(0, 4)
veggies = ['tomato', 'olives', 'onions', 'peppers', 'pineapple', 'mushrooms', 'tomato', 'olives', 'onions', 'peppers', 'pineapple', 'mushrooms']
selection = []
if i == 0:
return 'none'
else:
for n in range(i):
selection.append(veggies[random.randint(0, 11)])
return ' & '.join(set(selection))
def gen_pizza():
cheese = calc_cheese()
meats = calc_meats()
veggies = calc_veggies()
return Pizza(cheese, meats, veggies)
def random_pizzas(quantity):
pizzas = []
for _ in range(quantity):
pizzas.append(gen_pizza())
j_pizzas = json.dumps(pizzas, indent=4, cls=PizzaEncoder)
return j_pizzas