Python Forum

Full Version: Simple Freshman Python Coding Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I’m a freshman in high school and I have this assignment I have to finish for my computer science class. The coding is probably really simple to fix but I don’t have much knowledge of python and I feel like all the attempts I’ve made to fix my code ended up making the problem worse. I would really appreciate it if you guys could help me out.

The assignment: For this project you need to identify your online store and guide your user to select an option from 3 different categories (containing at least 3 options each) and a 4th category that has a multiplier (like ketchup packets). Then the user will be given a summary of their order and a total price.


*sorry in advance for my messy code!
My code:

from tabulate import tabulate
 
totalOrderList = []
total = 0.0
size = " "
flavor = " "
topping = " "
spoonCount = 0
request = " "
 
def runningTotal():
 print("Running total: " + "${:0.2f}".format (total) + ".\n")
 
table = [["Large", "$4.50", "A. Mango Tart", "1. Gummy Bears", "$0.25"], ["Medium", "$3.50", "B. Coffee", "2. Chocolate Chips", "$0.25"], ["Small", "$2.75", "C. Rocket Pop Sorbet", "3. Popping Boba", "$0.25"], ["    ", "    ", "D. Salted Caramel", "4. Mini M&Ms", "$0.25"], ["", "", "E. Plain Tart", "5. Strawberries", "$0.30"], ["    ", "    ", "F. Rich Chocolate", "6. Blueberries", "$0.30"], ["    ", "    ", "G. Fresh Strawberry", "7. Mango", "$0.30"], ["    ", "    ", "H. Cookies & Cream", "8. Pineapple", "$0.30"]]
headers = ["Froyo Size", " $", "Flavors", "Toppings", " $"]
print (tabulate(table, headers)
 
print("Welcome to Yogurtland! I am 001, your digital serverbot for today.")
 
def selSize():
 """global sizeOrder
 global size"""
 global total
 sizeOrder = input("\nWhich size frozen yogurt would you like? Please type in ONLY the FIRST letter of your desired size.\n")
 if sizeOrder == "L" or sizeOrder == "l":
   total += 4.50
   size = "large"
   print("You ordered a " + size + " frozen yogurt.")
   runningTotal()
 elif sizeOrder == "M" or sizeOrder == "m":
   total += 3.50
   size = "medium"
   print("You ordered a " + size + " frozen yogurt.")
   runningTotal()
 elif sizeOrder == "S" or sizeOrder == "s":
   total += 2.75
   size = "small"
   print("You ordered a " + size + " frozen yogurt.")
   runningTotal()
 else:
   print("Invalid input. Please make sure you have typed in the correct letter.")
  
 
def selFlav():
 """global flavOrder
 global flavor"""
 global total
 flavOrder = input("\n\nWhich flavor would you like to choose? Please make sure to input the correct letter.\n")
 if flavOrder == "A" or flavOrder == "a":
   flavor = "Mango Tart"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "B" or flavOrder == "b":
   flavor = "Coffee"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "C" or flavOrder == "c":
   flavor = "Rocket Pop Sorbet"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "D" or flavOrder == "d":
   flavor = "Salted Caramel"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "E" or flavOrder == "e":
   flavor = "Plain Tart"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "F" or flavOrder == "f":
   flavor = "Rich Chocolate"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "G" or flavOrder == "g":
   flavor = "Fresh Strawberry"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 elif flavOrder == "H" or flavOrder == "h":
   flavor = "Cookies & Cream"
   print("You have chosen " + flavor + " as your frozen yogurt flavor.")
   runningTotal()
 else:
   print("Invalid input. Please make sure you have typed in the correct letter.")
  
 
def selTop():
 """global topOrder
 global topping"""
 global total
 topOrder = input("\n\nWhich topping would you like? Make sure to input the correct number. Please type '0' if you do not want any toppings.\n")
 if topOrder == "0" :
   topping = "no topping"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "1" :
   total += 0.25
   topping = "Gummy Bears"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "2" :
   total += 0.25
   topping = "Chocolate Chips"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "3" :
  total += 0.25
  topping = "Popping Boba"
  print ("You chose " + topping)
  runningTotal()
 elif topOrder == "4" :
   total += 0.25
   topping = "Mini M&Ms"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "5" :
   total += 0.30
   topping = "Strawberries"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "6" :
   total += 0.30
   topping = "Blueberries"
   print("You chose " + topping)
   runningTotal()
 elif topOrder == "7" :
  total += 0.30
  topping = "Mango"
  print ("You chose " + topping)
  runningTotal()
 elif topOrder == "8" :
   total += 0.30
   topping = "Pineapple"
   print("You chose " + topping)
   runningTotal()
 else:
   print("Invalid input. Please make sure you have typed in the correct number.")
  
def spoonNumb():
 """global spoonCount"""
 global total
 spoonCount = int(input("\n\nOur limited edition spoon theme for this month is Animal Crossing! Our spoon designs include K.K. Slider, Isabelle, Tom Nook, Timmy and Tommy Nook, Blathers, and Flick! Spoon designs will be chosen randomly but we will take design requests. How many spoons would you like? Please input the number of spoons you want. * Note that spoons are limited to 10 per order.\n"))
 if spoonCount <= 10:
   print(spoonCount + " spoons will be added to your order.")
 else:
   print("You cannot order more than 10 spoons per order.")
  
 
def spoonRequest():
 """global request"""
 request = input("Do you have any special instructions or spoon requests? Please type 'no' if not.")
 
 
def checkOut():
 print[*totalOrderList, sep = "\n"]
 print("\n* FINAL ORDER * \n" + size + flavor + "flavored" + " frozen yogurt with " + topping")
 print("Spoons:" + spoonCount)
 print("\n Final cost: " + "${:0.2f}".format (total) + ".")
 print("\nSpecial Instructions/Spoon Requests:" + request)
Please, fix the indentation in your code - some times you have 1 space and some times - 2 spaces per level. Also use 4 spaces per indentation level, as per PEP8 recommendation. In any case using just one space per level makes it very hard to read your code.
I think that your indentation is wrong. Please tend to it
You need to be way more specific about the requirements - what exactly is the difference between them and the current behavior of your code?