Nov-28-2022, 09:04 PM
purchase = 1 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 ("shop:"+str(shop)) f.write (" ; ") f.write ("SIP:"+str(sipCard)) f.write (" ; ") f.write ("expiry:"+str(sipCardexipirationDate)) f.write (" ; ") f.write ("£:"+str(cost)) f.write ("\n") exit 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] 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") while purchase <200: write() read()
Output:What shop did you shop at?gucci
What is your sip card?123
please write the years left before the expiry date (to the nearest year) 2
Please enter the total cost of the shop you have shopped at123.45
shop:gucci ; SIP:123 ; expiry:2 ; £:123.45
what is your name?mehri
Error:Traceback (most recent call last):
File "C:/Users/StaR/AppData/Local/Programs/Python/Python311/file3.py", line 43, in <module>
read()
File "C:/Users/StaR/AppData/Local/Programs/Python/Python311/file3.py", line 30, in read
sipCardexipirationDate = int(line.split(" ; ")[1].replace("\n",""))
ValueError: invalid literal for int() with base 10: 'SIP:123'