We’re doing a school musical, I’m on the enterprise team, details unimportant. I agreed to make a way to keep track of ticket sales, I have this simple code but my problem is I need a way to save the data I record with it. From what I found the best way to do that is with JSON (if you can think of a better way that’ll help too ) but I’m really struggling to get my head around how it works and how to incorporate it into my code, can anyone help me out?
what i have so far:
names = [["sample name one"],["sample name two"],["sample name three"]] #list of names, sample name to avoid issue with ticket 0
z = False #unused varible, just to create infinite loop
price = 10
while z == False: #infinite loop
run = input("what would you like to do? ") #user chooses action
if run == "sell": #sell tickets
name = input("name? ") #name of buyer
night = int(input("night? "))-1
names[night].append(name)
print("ticket number:",len(names[night])) #ticket number is just where you are on the list
if run == "check": #shows list of who has what ticket and how much money there should be
for j in range (3):
print("night:",j+1)
print("name\tticket #")
for i in range (len(names[j])):
print(names[j][i],"\t",i)
print("€",(len(names[j])-1)*price) #money from one night
print()
print("€",(len(names[0]+names[1]+names[2])-3)*price," total") #money from all nights
print()
planning on adding stuff like a search system through the names but I figured saving would be more important to do first, apologies for my comments I don’t know fancy coding lingo I tried my best haha, still a beginner.