Day 052 - Project 52 : Pizza Pricer with Save/Load no crashing on non-int

If you have any questions, comments or issues with this project please post them here!

Hello Ian, I am on day 52 and am experiencing a problem. The code works except the .txt file is not getting appended, so the file and the viewing table is blank. I checked my code and it is very similar to the solution. If you could explain why this is happening, that would be great!
Thank you

Hey, @roninMehendale welcome to the forums!

Can you please provide a link to your repl?

1 Like

https://replit.com/@RadhikaMehendal/R-Day-52?v=1

In this case, you might actually want to use "w" instead of "a". Each time you read all the orders into the pizza list so when you write to the file, you are adding a whole new list. Instead, you should just overwrite the file with the pizza list and then it should work.

Thank you so much MattDESTROYER and not-ethan, your advice really helped!

3 Likes

Here’s my solution! Seems to work :slight_smile:

import os, time

debugMode=False
orders=[]

def autoLoad():
  global orders
  f=open("pizzas.txt", "r")
  orders=eval(f.read())
  f.close()

def autoSave():
  f=open("pizzas.txt", "w")
  f.write(str(orders))
  f.close()

try:
  autoLoad()

except Exception as err:
  print("Error: unable to load.")
  print(err)
  if debugMode:
    print(traceback)

def prettyPrint():
  global orders
  for row in orders:
    print(f"Name: {row[0]}, {row[1]} {row[2].upper()} Pizza(s).\nOrder Total = {row[3]}")
    print()
  print()
  time.sleep(3)
  os.system("clear")
  
def add():
  time.sleep(1)
  os.system("clear")
  pCost=0
  pizzaQ=0
  pizzaSz=""
  totalCost=0
  try:
    name=input("Name on the order: \n> \033[36m")
    print("\033[0m")
    pizzaQ=int(input("How many pizzas?\n> \033[36m"))
    print("\033[0m")
  except:
    print("Must enter a whole number (ex: 1, 3, 45, etc)\nTry again.")
    time.sleep(2)
    return
    
  pizzaSz=input("What size? (type S, M, L)").strip().lower()
  if pizzaSz=="s":
    pCost=5.99
  elif pizzaSz=="m":
    pCost=9.99
  elif pizzaSz=="l":
    pCost=13.99
  else:
    print("Not an option. Start over.")
    time.sleep(2)
    return
  totalCost=float(round(((float(pizzaQ)) * pCost), 2))

  time.sleep(1)
  os.system("clear")

  print(f"Thank you, {name}.")
  print()
  print(f"{pizzaQ} pizza(s) sized {pizzaSz.upper()}\nat {pCost} per {pizzaSz.upper()}")
  print(f"comes out to ${totalCost}")
  time.sleep(1)

  row=[name, pizzaQ, pizzaSz, totalCost]
  orders.append(row)

  autoSave()
  time.sleep(2)
  os.system("clear")
  
def view():
  time.sleep(1)
  os.system("clear")
  print("Current Orders:")
  prettyPrint()

while True:
  menu=input("add order\nview current orders\ntype 'add' or 'view'\n> \033[36m")
  print("\033[0m")
  if menu=="add":
    add()

  elif menu=="view":
    view()```

Hi, I keep getting this error when trying to test run my code: repl process died unexpectedly: signal: killed

image

image

I mean, you put the resources screenshot there, that’s a likely reason why then…

Yes that’s why I included it but can a small piece of code cause this?

It could be some kind of overload or something? I don’t know since I haven’t done the 100 days of Python before, but it is most likely related to those high levels

1 Like

I think I can track it down to a while True: loop that may be ‘slightly’ dysfunctional.

I had visions of not being able to complete the 100 days unless you had to purchase a mega account or something!