Skip to content

Commit 03b3f6d

Browse files
authored
Pizza order python script (#391)
* Adding Pizza Order Project files Creating Pull Request to add new Python Project "Pizza Order" * Update README.md
1 parent 3949851 commit 03b3f6d

File tree

6 files changed

+312
-0
lines changed

6 files changed

+312
-0
lines changed

Pizza Order/PizzaTest.py

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import subprocess
2+
3+
4+
def runTest (file, inText):
5+
if file =="order":
6+
res = subprocess.run("python " + file + ".py", input=inText, capture_output=True, text=True, shell=True)
7+
return res.stdout
8+
9+
if file == "pizzaReceipt":
10+
res = subprocess.run("python -c \"from pizzaReceipt import *; generateReceipt([" +inText+ "])\"", capture_output=True, text=True, shell= True)
11+
return res.stdout
12+
13+
14+
def equalWithoutSpaces(expected, student):
15+
expected = expected.replace(" ", "")
16+
expected = expected.replace("\t", "")
17+
student = student.replace(" ", "")
18+
student = student.replace("\t", "")
19+
return expected == student
20+
21+
22+
23+
# --------------- Test 1 - No Order---------------
24+
25+
inputString = ""
26+
studentOutput = runTest("pizzaReceipt", inputString)
27+
expectedOutput = "You did not order anything\n"
28+
29+
# Compare studentOutput to expectedOutput
30+
if studentOutput == expectedOutput:
31+
print("Test 1 Passed. (Receipt for empty order)")
32+
else:
33+
print("Test 1 Failed. (Receipt for empty order)")
34+
35+
#print(studentOutput)
36+
37+
# --------------- Test 2 - List of Orders---------------
38+
39+
inputString = "('L', ['HAM', 'BACON', 'ONION', 'TOMATO']), ('S', ['PEPPERONI', 'SAUSAGE', 'CHICKEN', 'HAM']), ('L', ['BROCCOLI', 'CHICKEN', 'ONION'])"
40+
studentOutput = runTest("pizzaReceipt", inputString)
41+
expectedOutput = "Your order: \nPizza 1: L 11.99\n- HAM\n- BACON\n- ONION\n- TOMATO\nExtra Topping (L) 1.00\n"
42+
expectedOutput += "Pizza 2: S 7.99\n- PEPPERONI\n- SAUSAGE\n- CHICKEN\n- HAM\nExtra Topping (S) 0.50\n"
43+
expectedOutput += "Pizza 3: L 11.99\n- BROCCOLI\n- CHICKEN\n- ONION\nTax: 4.35\nTotal: 37.82\n"
44+
45+
# Compare studentOutput to expectedOutput
46+
#if studentOutput == expectedOutput:
47+
if equalWithoutSpaces(expectedOutput, studentOutput):
48+
print("Test 2 Passed. (Receipt for empty order of 3 pizzas)")
49+
else:
50+
print("Test 2 Failed. (Receipt for empty order of 3 pizzas)")
51+
52+
53+
# --------------- Test 3 - List of Orders---------------
54+
55+
inputString = "('XL', ['GREEN PEPPER', 'HOT PEPPER', 'MUSHROOM', 'ONION', 'SPINACH']), ('L', ['PEPPERONI', 'ONION', 'OLIVE', 'MUSHROOM']), ('L', ['PINEAPPLE', 'HAM']), ('M', ['GROUND BEEF', 'TOMATO', 'ONION', 'SPINACH'])"
56+
studentOutput = runTest("pizzaReceipt", inputString)
57+
expectedOutput = "Your order: \nPizza 1: XL 13.99\n- GREEN PEPPER\n- HOT PEPPER\n- MUSHROOM\n- ONION\n- SPINACH\nExtra Topping (XL) 1.25\n"
58+
expectedOutput += "Extra Topping (XL) 1.25\nPizza 2: L 11.99\n- PEPPERONI\n- ONION\n- OLIVE\n- MUSHROOM\n"
59+
expectedOutput += "Extra Topping (L) 1.00\nPizza 3: L 11.99\n- PINEAPPLE\n- HAM\nPizza 4: M 9.99\n"
60+
expectedOutput += "- GROUND BEEF\n- TOMATO\n- ONION\n- SPINACH\nExtra Topping (M) 0.75\nTax: 6.79\nTotal: 59.00\n"
61+
62+
# Compare studentOutput to expectedOutput
63+
if equalWithoutSpaces(expectedOutput, studentOutput):
64+
print("Test 3 Passed. (Receipt for empty order of 4 pizzas)")
65+
else:
66+
print("Test 3 Failed. (Receipt for empty order of 4 pizzas)")
67+
68+
# --------------- Test 4 - Find Specific Values in Output ---------------
69+
70+
studentOutput = runTest("order", "Yes\nL\nHAM\nX\nNo\n")
71+
72+
if studentOutput.find("13.55") != -1:
73+
print("Test 4 Passed. (Ordering system for order of 1 pizza)")
74+
else:
75+
print("Test 4 Failed. (Ordering system for order of 1 pizza)")
76+
77+
#print(studentOutput)
78+
79+
# --------------- Test 5 - Find Specific Values in Output---------------
80+
81+
studentOutput = runTest("order", "Yes\nmedium\nM\nLIST\npepperoni\nonion\nmushroom\nhot pepper\ntomato\nX\nq\n")
82+
83+
if studentOutput.find("\"X\"\n('") != -1 and studentOutput.count("Choose a size:") == 2 and studentOutput.count("Type in one of our toppings") == 7 and studentOutput.find("1.49") != -1 and studentOutput.find("12.98") != -1:
84+
print("Test 5 Passed. (Ordering system with typo and use of LIST)")
85+
else:
86+
87+
print("Test 5 Failed. (Ordering system with typo and use of LIST)")
88+
89+
print()
90+
print(studentOutput.find("\"X\"\n('") != -1)
91+
print(studentOutput.count("Choose a size:") == 2)
92+
print(studentOutput.count("Type in one of our toppings") == 7)
93+
print(studentOutput.find("1.49") != -1)
94+
print(studentOutput.find("12.98") != -1)
95+
print()
96+
97+
# --------------- Find Specific Values in Output ---------------
98+
99+
studentOutput = runTest("order", "y\nm\nsausage\nbacon\nonion\nX\ny\nXl\nchicken\ntomato\nspinach\nmushroom\nx\ny\nm\nolive\nbroccoli\nhot pepper\ngreen pepper\nx\nno\n")
100+
101+
if studentOutput.count("Type in one of our toppings") == 14 and studentOutput.find("4.68") != -1 and studentOutput.find("40.65") != -1:
102+
print("Test 6 Passed. (Ordering system for order of 3 pizzas)")
103+
else:
104+
print("Test 6 Failed. (Ordering system for order of 3 pizzas)")
105+
106+
# print(studentOutput)
107+
# print(expectedOutput)
108+
# --------------------------------
109+
110+
111+
112+

Pizza Order/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# OrderPizza
2+
A program that I created in one of my computer science courses containing a frontend and backend. The frontend deals with asking the user for their order, while the backend focuses on storing the information in a receipt format along with its calculations by using functions, lists, and tuples.
3+
4+
In the frontend, the user first asks if the customer would like to order. If they say no, the code exits completely and is terminated. If the user says yes, it will then ask for the size of pizza as each have a different price range. After, the user will ask for toppings. The maximum that they can enter is three. Afterwards, every topping will cost an additional price to its total. After they have completed asking toppings, the program creates the order in a tuple and is stored in a variable. If the user would like to continue to ordering, the program would loop once more using a while loop and repeat the same questions that were asked in the last instance Afterwards, the second order is incremented to the variable containing the tuple. Otherwise, the code exits and the pizza receipt file is called using the variable of the tuple containing the pizza order and will print a receipt detailing the order and the total.
5+
6+
In the backend, once the customer has finished ordering, the function is called using the variable as a paramter containing the customers order and creates a receipt by first showing the first pizza, its size, toppings and the amount is placed on the right hand side. If there are more than three toppings, it will show its additional cost as well. If there are more pizzas included, it will repeat the process once more. Afterwards, it shows the total before tax, the additional 13% tax in dollar amount and the total with tax.

Pizza Order/order.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# purpose of order.py is the front end for users to submit their order
2+
from pizzaReceipt import * # asks to import all functions found in the pizzaReceipt.py file
3+
4+
# set all initial variables before beginning
5+
size = ""
6+
pizza_lst = []
7+
pizza_lst_current = []
8+
toppings_lst = [] # list to be a parameter for generateReceipt function
9+
list_order_yes = ["Yes", "yes", "Y", "y", "YES"]
10+
list_order_no = ["No", "no", "Q", "NO", "N", "n"]
11+
TOPPINGS = ("ONION", "TOMATO", "GREEN PEPPER", "MUSHROOM", "OLIVE", "SPINACH", "BROCCOLI", "PINEAPPLE",
12+
"HOT PEPPER", "PEPPERONI", "HAM", "BACON", "GROUND BEEF", "CHICKEN", "SAUSAGE")
13+
14+
# ask user whether they want to order.
15+
order = input("Do you want to order a pizza? ")
16+
17+
# case for when an invalid input is submitted
18+
while (order not in list_order_yes) and (order not in list_order_no):
19+
order = input("Do you want to order a pizza? ")
20+
21+
# ask for size
22+
if order in list_order_yes:
23+
size = input("Choose a size: ")
24+
size.upper()
25+
26+
# case for when a user inputs invalid size
27+
while size.upper() not in ["S", "M", "L", "XL"]:
28+
size = input("Choose a size: ")
29+
30+
# entire loop to repeat if user wants to order more than one pizza
31+
while order in list_order_yes:
32+
# set empty toppings list as it will show empty each time loop is made
33+
toppings_lst = []
34+
# ask user for topping, whether they want to see a list of the toppings, or to finish ordering toppings.
35+
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
36+
'When you are done adding toppings, enter "X" ')
37+
38+
# cae for when a user places an invalid input for this question
39+
while (topping.upper() != "X") and (topping.upper() != "LIST") and (topping.upper() not in TOPPINGS):
40+
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
41+
'When you are done adding toppings, enter "X" ')
42+
43+
print()
44+
# toppings while loop which ask for toppings selection or list view, multiple times until user enters X
45+
while topping.upper() != "X":
46+
TOPPINGS = ("ONION", "TOMATO", "GREEN PEPPER", "MUSHROOM", "OLIVE", "SPINACH", "BROCCOLI", "PINEAPPLE",
47+
"HOT PEPPER", "PEPPERONI", "HAM", "BACON", "GROUND BEEF", "CHICKEN", "SAUSAGE")
48+
if topping.upper() == "LIST":
49+
print(topping.upper())
50+
print(TOPPINGS)
51+
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
52+
'When you are done adding toppings, enter "X" \n \n')
53+
elif topping.upper() in TOPPINGS:
54+
print(topping.upper())
55+
print("Added", topping.upper(), "to your pizza")
56+
toppings_lst.append(topping)
57+
topping = input('Type in one of our toppings to add it to your pizza. To see the list of toppings, enter "LIST". '
58+
'When you are done adding toppings, enter "X" \n \n')
59+
60+
# add the size and toppings list as a tuple to pizza_lst
61+
pizza_lst.append((size.upper(), toppings_lst))
62+
print(pizza_lst)
63+
# ask whether they want to continue ordering
64+
order = input("Do you want to continue ordering? ")
65+
66+
# case for when user types invalid input
67+
while (order not in list_order_yes) and (order not in list_order_no):
68+
order = input("Do you want to order a pizza? ")
69+
70+
# if they say no, break the loop and go through the last line of the code
71+
if order in list_order_no:
72+
break
73+
elif order in list_order_yes:
74+
size = input("Choose a size: ") # if they want to order again start by asking size
75+
76+
# case for when user types invalid input
77+
while size.upper() not in ["S", "M", "L", "XL"]:
78+
size = input("Choose a size: ")
79+
80+
generateReceipt(pizza_lst) # at the end of program, call function using pizza_lst as a parameter

Pizza Order/pizzaReceipt.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# purpose of pizzaReceipt.py is the back end where the developers create methods and functions to properly format the receipt and its total
2+
def generateReceipt(pizzaOrder):
3+
# parameter will be placed with pizza_lst = ("M", ["PEPPERONI", "OLIVE"], -----)
4+
# set initial variables
5+
size = ""
6+
additional_price = 0
7+
price_before_tax = 0
8+
tax = 1.13
9+
counter = 1 # pizza number
10+
size_price = 0
11+
additional_price_tag = float(0)
12+
additional_price_tag_format = ""
13+
14+
# if its an empty list, display this statement
15+
if len(pizzaOrder) == 0:
16+
print("You did not order anything")
17+
exit()
18+
19+
# beginning of the format of receipt
20+
print("Your order: ")
21+
22+
# a for loop which goes through all tuples in the list based on its indices
23+
for pizza in range(len(pizzaOrder)):
24+
# cases to determine the sizes selected and its price
25+
if pizzaOrder[pizza][0] == "S":
26+
size_price = 7.99
27+
size = "S"
28+
elif pizzaOrder[pizza][0] == "M":
29+
size_price = 9.99
30+
size = "M"
31+
elif pizzaOrder[pizza][0] == "L":
32+
size_price = 11.99
33+
size = "L"
34+
elif pizzaOrder[pizza][0] == "XL":
35+
size_price = 13.99
36+
size = "XL"
37+
38+
# add the price of the size to the final price before tax
39+
price_before_tax += size_price
40+
41+
# formatting the pizza number and its size beside it and the price on the other side
42+
if size == "XL":
43+
print("Pizza", str(counter) + ":", str(size) + " \t\t\t " + str(size_price))
44+
elif size == "L":
45+
print("Pizza", str(counter) + ":", str(size) + " \t\t\t " + str(size_price))
46+
elif size == "M":
47+
print("Pizza", str(counter) + ":", str(size) + " \t\t\t " + str(size_price))
48+
elif size == "S":
49+
print("Pizza", str(counter) + ":", str(size) + " \t\t\t " + str(size_price))
50+
51+
# increment counter variable by one for the pizza number
52+
counter += 1
53+
54+
# format the toppings with a dash in front
55+
for j in range(len(pizzaOrder[pizza][1])):
56+
print("- " + str(pizzaOrder[pizza][1][j]))
57+
58+
# if theres more than three toppings, calculate the total additional price and added to the total price before tax
59+
if len(pizzaOrder[pizza][1]) > 3:
60+
n = len(pizzaOrder[pizza][1]) - 3
61+
if size == "S":
62+
additional_price_tag = 0.50
63+
additional_price_tag_format = "{:.2f}".format(additional_price_tag)
64+
additional_price = 0.50 * n
65+
price_before_tax += additional_price
66+
elif size == "M":
67+
additional_price_tag = 0.75
68+
additional_price = 0.75 * n
69+
price_before_tax += additional_price
70+
elif size == "L":
71+
additional_price_tag = 1.00
72+
additional_price_tag_format = "{:.2f}".format(additional_price_tag)
73+
additional_price = 1.00 * n
74+
price_before_tax += additional_price
75+
elif size == "XL":
76+
additional_price_tag = 1.25
77+
additional_price = 1.25 * n
78+
price_before_tax += additional_price
79+
80+
# format the extra topping portion of the receipt with its size and price on the other side
81+
float_additional_price = float(additional_price)
82+
format_additional_price = "{:.2f}" .format(float_additional_price)
83+
84+
for extra in range(len(pizzaOrder[pizza][1])):
85+
if extra > 2:
86+
if size == "XL":
87+
print("Extra Topping", "(" + size + ")" + "\t\t " + str(additional_price_tag))
88+
elif size == "L":
89+
print("Extra Topping", "(" + size + ")" + "\t\t " + str(additional_price_tag_format))
90+
elif size == "M":
91+
print("Extra Topping", "(" + size + ")" + "\t\t " + str(additional_price_tag))
92+
elif size == "S":
93+
print("Extra Topping", "(" + size + ")" + "\t\t " + str(additional_price_tag_format))
94+
# outside of loop begins, calculates the price before tax with the tax value set earlier
95+
price_final = price_before_tax * tax
96+
97+
# add the tax price to be added and set it to a float, as well as the final price with tax
98+
float1 = float(price_before_tax * (13/100))
99+
float2 = float(price_final)
100+
formatFloat1 = "{:.2f}" .format(float1)
101+
formatFloat2 = "{:.2f}" .format(float2)
102+
103+
# format the price of the tax, and the total with both values on the other side
104+
print("Tax:" + "\t\t\t\t\t " + formatFloat1)
105+
print("Total:" + "\t\t\t\t\t " + formatFloat2)

Pizza Order/pyvenv.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
home = /Library/Frameworks/Python.framework/Versions/3.10
2+
implementation = CPython
3+
version_info = 3.10.0.final.0
4+
virtualenv = 20.13.0
5+
include-system-site-packages = false
6+
base-prefix = /Library/Frameworks/Python.framework/Versions/3.10
7+
base-exec-prefix = /Library/Frameworks/Python.framework/Versions/3.10
8+
base-executable = /usr/local/bin/python3.10

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ More information on contributing and the general code of conduct for discussion
110110
| PDF to Audio | [PDF to Audio](https://github.com/DhanushNehru/Python-Scripts/tree/master/PDF%20to%20Audio) | Converts PDF to audio. |
111111
| PDF to Text | [PDF to text](https://github.com/DhanushNehru/Python-Scripts/tree/master/PDF%20to%20text) | Converts PDF to text. |
112112
| PDF merger and splitter | [PDF Merger and Splitter](https://github.com/AbhijitMotekar99/Python-Scripts/blob/master/PDF%20Merger%20and%20Splitter/PDF%20Merger%20and%20Splitter.py) | Create a tool that can merge multiple PDF files into one or split a single PDF into separate pages. |
113+
| Pizza Order | [Pizza Order](https://github.com/DhanushNehru/Python-Scripts/tree/master/Pizza%20Order) | An algorithm designed to handle pizza orders from customers with accurate receipts and calculations. |
113114
| Planet Simulation | [Planet Simulation](https://github.com/DhanushNehru/Python-Scripts/tree/master/Planet%20Simulation) | A simulation of several planets rotating around the sun. |
114115
| Playlist Exchange | [Playlist Exchange](https://github.com/DhanushNehru/Python-Scripts/tree/master/Playlist%20Exchange) | A Python script to exchange songs and playlists between Spotify and Python. |
115116
| Pigeonhole Sort | [Algorithm](https://github.com/DhanushNehru/Python-Scripts/tree/master/PigeonHole) | The pigeonhole sort algorithm to sort your arrays efficiently! |

0 commit comments

Comments
 (0)