Skip to content

Instantly share code, notes, and snippets.

@MichelePipi
Created June 29, 2021 00:58
Show Gist options
  • Save MichelePipi/ed87f05a0d902e801910847c87638a3e to your computer and use it in GitHub Desktop.
Save MichelePipi/ed87f05a0d902e801910847c87638a3e to your computer and use it in GitHub Desktop.
Python Assignment
import time
# Write a program for a McDonalds Happy Meal ordering app
# At the end of the program, it should print out something like this
#
# Happy Meal 1 wants nuggets, fries, juice and doll
# Happy Meal 2 wants cheeseburger, fruit, juice and car
# Happy Meal 3 wants cheeseburger, fries, soda and car
# The total cost is 15 dollars
#
# T1: Make a variable called total and set the start value to 0
debug_mode = False
debug_choice = input("Would you like to enable Debug Mode? ('True', or 'False') ")
if debug_choice == 'True':
debug_mode = True
else:
debug_mode = False
print("True not entered, debug mode was disabled.")
time.sleep(3)
total_price = 0
if debug_mode:
print("total_price set to 0")
# T2: Ask the user how many Happy Meals they want to order
amount = 0
if debug_mode:
print("amount set to 0")
happy_meal_count_done = False
if debug_mode:
print("happy_meal_count_done set to False")
while not happy_meal_count_done:
try:
amount = int(input("How many Happy Meals do you want to order? "))
if debug_mode:
print("amount attempted to be initialized")
happy_meal_count_done = True
if debug_mode:
print("happy_meal_count_done set to True")
except ValueError:
print("Input cannot be interpreted as an integer.")
if debug_mode:
print("ValueError was caught.")
# Hint: make a variable to remember how many they order
happy_meals = []
main_foods = ['cheeseburger', 'nuggets']
snacks = ['fries', 'fruit']
drinks = ['juice', 'soda']
genders = ['boy', 'girl', 'woman', 'man']
if debug_mode:
print("""
happy_meals set to empty list
main_foods set to list with contents 'cheeseburger', and 'nuggets'
snacks set to list with contents 'fries', and 'fruit'
drinks set to list with contents 'juice', and 'soda'
genders set to list with contents 'boy', 'girl', 'woman', 'man'
""")
total_price = amount * 5 # Total price of all the Happy Meals.
if debug_mode:
print("total_price set to", total_price)
for i in range(1, amount + 1): # Loop with iterator i, starting at 1, and ending at the amount of happy meals (plus
# one)
if debug_mode:
print("For Loop started with range beginning at 1, and ending at", amount + 1)
done = False # Initialize boolean done with value 0 (False)
if debug_mode:
print("done set to False")
toy = '' # Initialize empty string toy, with value ''
if debug_mode:
print("toy set to ''")
main_food = '' # Initialize empty string main_food, with value ''
if debug_mode:
print("main_food set to ''")
while not done:
if debug_mode:
print("While Loop started with condition: while done != True")
main_food = input("Do you want nuggets or a cheeseburger? ").lower()
if debug_mode:
print("Value of main_food attempted to be changed.")
if main_food not in main_foods:
if debug_mode:
print("Selected food was not in main_foods list")
print("Please choose 'nuggets' or 'cheeseburger.'")
else:
done = True
if debug_mode:
print("done set to True.")
done = False
snack = ''
if debug_mode:
print("""
done set to False
snack set to ''""")
while not done:
if debug_mode:
print("While Loop started with condition: while done != True")
snack = input("Do you want fries or fruit? ").lower()
if debug_mode:
print("Value of snack was attempted to be changed.")
if snack not in snacks:
if debug_mode:
print("snack is not in snacks list.")
print("Please choose 'fries' or 'fruit.'")
else:
if debug_mode:
print("done set to True.")
done = True
done = False
if debug_mode:
print("done set to False.")
drink = ''
if debug_mode:
print("drink set to ''")
while not done:
if debug_mode:
print("While Loop started with condition: while done != True")
drink = input("Do you want juice or soda? ").lower()
if debug_mode:
print("Value of drink was attempted to be changed.")
if drink not in drinks:
if debug_mode:
print("Value of drink is not in drinks list.")
print("Please choose 'juice' or 'soda.'")
else:
if debug_mode:
print("done set to True.")
done = True
done = False
if debug_mode:
print("done set to False.")
gender = '' # Initialize empty string gender ('')
if debug_mode:
print("gender set to ''")
while not done: # While done is not True
if debug_mode:
print("While Loop started with condition: while done != True")
gender = input("Is the child a boy or a girl? ").lower() # Gender set to the value of the input, lowercase.
if debug_mode:
print("Value of gender was attempted to be changed.")
if gender not in genders: # If the input is not one of the genders in the list ('boy', 'girl')
print("Please choose 'boy' or 'girl.'")
if debug_mode:
print("Value of gender not in genders list.")
else: # Otherwise
done = True # Done
if debug_mode:
print("done set to True.")
if gender == 'boy': # If the gender is a boy
toy = 'car' # Set the toy to a car
if debug_mode:
print("Value of gender is 'boy'.")
elif gender == 'girl': #
toy = 'doll'
if debug_mode:
print("Value of gender is 'girl'.")
happy_meals.append([main_food, snack, drink, gender, toy])
if debug_mode:
print("""
happy_meals value appended:
""" + main_food +
"""
""" + snack +
"""
""" + drink +
"""
""" + gender +
"""
""" + toy + "\n")
print("Happy Meal", i, "wants", main_food + ',', snack + ',', drink + ",", "and a", toy + '.')
if debug_mode:
print("Happy Meal ending printed")
print("The total cost for all of your happy meals is: $" + str(total_price))
if debug_mode:
print("We done here")
print("""Contents of happy_meals list:""")
for list in happy_meals:
print(list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment