Nov-27-2022, 07:23 PM
(This post was last modified: Nov-27-2022, 07:23 PM by MehHz2526.
Edit Reason: Fixed code tags
)
def reciept(): name =input("what is your name?") sipCard =int(input("What is your sip card")) twoforone =int(input("How many of the two for one deals would you like?")) #monthly record with open ("MonthlyRecord.txt","w")as f: f.write (f'{name}\n{sipCard}\n{twoforone}') with open ("MonthlyRecord.txt","r") as f: print(f.read()) def write(): shop =input("What shop did you shop at?") sipCard =int(input("What is your sip card?")) sipCardexipirationDate = int(input("please write the years left before the expiry date (to the nearest year) ")) cost =float(input("Please enter the total cost of the shop you have shopped at")) #monthly record with open ("MonthlyRecord.txt","w")as f: f.write (f'{shop}\n{sipCard}\n{sipCardexipirationDate}\n{cost}') with open ("MonthlyRecord.txt","r") as f: print(f.read()) def read(): lookfor = input ("what is your name?") with open("MonthlyRecord.txt", "r") as f: for line in f.readlines(): sipCard = line.split(" ; ")[0] global sipCardexipirationDate sipCardexipirationDate = int(line.split(" ; ")[1].replace("\n","")) if sipCard == lookfor: print(sipCardexipirationDate) choice = input("pick 1 or 2") if choice == "1": write() else: read() print ("thank you") def discount(): shopToday= input("Please type the shop you have shopped at ?") if shopToday =="1": discount1 = totalCost1/10 finalCost = (totalCost1 - discount1)+ totalCost2 +totalCost3 print("£:",finalCost) if shopToday =="2": discount2 = totalCost2/10 finalCost = (totalCost2 - discount2)+ totalCost1 +totalCost3 print("£:",finalCost) if shopToday =="3": discount3 = totalCost3/10 finalCost = (totalCost3 - discount3)+ totalCost2 +totalCost1 print("£:",finalCost) write() read() totalCost1= float(input("what is your1st total cost?")) totalCost2=float(input("what is your1st total cost?")) totalCost3=float(input("what is your1st total cost?")) discount() #delivery part shopToday=input("Depending on the day of the week, you can get free delivery. Please enter the day of the week.") if shopToday == "1" or shopToday== "2": location = int(input("Can you please give the distance between the shop to your place in km full number .")) if location == 5 or location <5 : print ("Okay, your delivery is being sent,right now") if location > 5: farLocation= input("Sorry we cannot deliver your items, would you like to pick up your purchasements?") if farLocation =="yes": print ("Okay,we will reserve your purchasements.") if farLocation =="no": print("Sorry for this issue, we will now delete your purchasements.") end = input("Thank you for purchasing our products, would you like to recieve an reciept?") if end == "no": print("Then please enjoy your time,goodbye") if end == "yes": reciept()
Error: File "main.py", line 61, in <module>
read()
File "main.py", line 35, in read
sipCard = int(line.split(" ; ")[1].replace("\n",""))
IndexError: list index out of range