Descripton: This is my culminating project for the Girl Develop It! course, Python I: Learning Cohort.
Through the creation of this interactive pizza order form, I was able to practice all that I learned during the 12-hour course: data types/espressions, variables, functions, conditionals, loops, and data structures. The project was designed with a perfect balance of independent challenges and support. I now feel more confident in writing Python, and I am happy that a lot of what I learned is transferrable to JavaScript, which is my next area of focus.
size_prices = {
"small": [12, .50],
"medium": [16, .75],
"large": [18, 1]
}
def order_pizza():
pizza_order = {
"customer_name": "",
"size": "",
"num_toppings": 0,
"toppings": []
}
pizza_order["customer_name"] = input("What is your name? ")
pizza_order["size"] = input("What size pizza would you like (small, medium, or large)? ")
pizza_order["num_toppings"] = int(input("How many toppings would you like? "))
total_toppings = 0
while len(pizza_order["toppings"]) < pizza_order["num_toppings"]:
current_topping = input("What topping would you like? ")
pizza_order["toppings"].append(current_topping)
total_toppings += 1
return pizza_order
def calculate_price(pizza_order):
base_price = size_prices[pizza_order["size"].lower()][0]
per_topping_price = size_prices[pizza_order["size"].lower()][1]
toppings_total = pizza_order["num_toppings"] * per_topping_price
return base_price + toppings_total
pizza_order = order_pizza()
pizza_price = calculate_price(pizza_order)
print("Thank you for your order, " + pizza_order["customer_name"] + "! ")
print("Order: " + pizza_order["size"] + " pizza with " + str(pizza_order["num_toppings"])+ " toppings (" + ", ".join(pizza_order["toppings"]) + ")")
print("Total cost: $" + str(pizza_price))
- Live Site URL: Order The Pizza of Your Dreams using the Online Python IDE!
- View the execution of the program here.
Although this was a live class, I missed it, so I followed along with the recording. This actually worked out better, because I was able to pause the video throughout the project and challenge myself to attempt each part of the code independently, including research and debugging, before revealing the solutions. Then, upon viewing the solutions, I compared my code to the solution code, and made necessary corrections and adjustments. Step 3, calculating the total price, was the most challenging for me, but it was extremely fulfilling once I understood the logic of the solution. I wrote very detailed notes for myself in the description section of the commits, so that I may review them to track my learning. I should have also written brief summaries for each commit. I will be sure to always do so in the future.
- Python
My biggest take-away is to think logically! I really enjoyed deciphering the logic of the price calculator.
def calculate_price(pizza_order):
base_price = size_prices[pizza_order["size"].lower()][0]
per_topping_price = size_prices[pizza_order["size"].lower()][1]
toppings_total = pizza_order["num_toppings"] * per_topping_price
return base_price + toppings_total
Here is what I wrote about it in the commit description, "It was such an "aha" moment when I understood base_price = size_prices[pizza_order['size'].lower()][0]
! I see that we are filling in the key using the size input! And we must be sure to make it all lowercase so that it matches regardless of the user input!. . . .
My approach using if statements was commendable, and maybe it would have eventually worked if I had continued fixing all the bugs, but I like this approach of first calculating the base price, then the per topping price, the toppings total, and finally the base price plus the toppings total. It seems to be more logical, clear, and concise."
I plan to spend more time learning and practicing JavaScript and data structures and algorithims, then I want to come back to Python and continue coding along with the book Automate the Boring Stuff by Al Sweigart, and working on more projects in Python.
- Python I: Learning Cohort (6-class series) - This is the GDI Python course that I just completed.
- Python II: Learning Cohort (6-class series) - This is an upcoming GDI Python course that will be offered four times per year.
Faraja Thompson
I'd like to acknowledge my son and mentor DeForestt Thompson. His steadfast support and encouragement keep me motivated! Thanks for forcing me to use the command-line, Son <3 <3 <3.