Nov-28-2022, 09:04 PM
(This post was last modified: Nov-28-2022, 09:04 PM by MehHz2526.
Edit Reason: Added code tags
)
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'
Yoriz write Nov-28-2022, 08:59 PM:
Please post all code, output and errors (in their entirety) correctly between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (in their entirety) correctly between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.