When I call the choose account method it’s giving me the invalid literal error . Below is the attached code and message error . This code is a very rough simulation of an ATM it’s not perfected yet
class ATM:
def __init__(self):
self.balance=0.0
def checkingAccountFile(self):
self.file=open("checkingAccouunt.txt", "r")
content=self.file.read()
print(content)
self.file.close()
def savingsAccountFile(self):
self.file=open("savingsAccount.txt", "r")
content=self.file.read()
self.file.close()
def transfer(self):
self.account= int(input("Which account do you want to transfer money to? Press 1 for checking or 2 for savings"))
if self.account == 1:
transAmt= float(input("Enter transfer amount"))
self.balance = self.balance - transAmt
fl=open("checkingAccouunt.txt", "w")
s= str(transAmt)
fl.write(s)
print(" your new balance is ", self.balance)
elif self.account== 2:
transAmt=float(input("Enter transfer amount "))
self.balance=self.balance-transAmt
fl=open("savingsAccouunt.txt", "w")
s= str(transAmt)
fl.write(s)
print("your new balance is", self`Preformatted text`.balance)
return self.balance
def userInputForChecking(self):
self.pin=1234
self.userID=1223
pin_input=int(input("enter four digit id"))
userID_input=int(input("enter user id"))
count =0
atm=ATM()
if pin_input==self.pin and userID_input== self.userID:
print("access granted")
while count < 2:
print("choose option. \n1 Deposit\n2 Withdraw \n3 view balance \n4 Transfer money ")
option=int(input("enter an option 1,2 or 3"))
if option ==1:
dep=float(input("enter deposit amount"))
self.balance=self.balance+dep
print(self.balance)
elif option == 2:
w=float(input("enter withdraw amt"))
self.balance =self.balance-w
print(self.balance)
elif option == 3:
amt=self.balance
f=open("checkingsAccouunt.txt", "w")
s1=str(amt)
f.write(s1)
print("yoiur balance is ", amt)
elif option == 4:
atm.transfer()
else:
print("invalid selection")
count = count +1
break
def userInputForSaving(self):
self.pin=1234
self.userID=1223
pin_input=int(input("enter four digit id"))
userID_input=int(input("enter user id"))
count =0
atm=ATM()
if pin_input==self.pin and userID_input== self.userID:
print("access granted")
while count < 2:
print("choose option. \n1 Deposit\n2 Withdraw \n3 view balance \n4 Transfer money ")
option=int(input("enter an option 1,2 or 3"))
if option ==1:
dep=float(input("enter deposit amount"))
self.balance=self.balance+dep
print(self.balance)
elif option == 2:
w=float(input("enter withdraw amt"))
self.balance =self.balance-w
print(self.balance)
elif option == 3:
print("yoiur balance is ", self.balance)
elif option == 4:
atm.transfer()
else:
print("invalid selection")
count = count +1
break
def chooseAccount(self):
m1=ATM()
self.opt= int(input("Which Account do you want to do a trasnaction on? Press 1 for checkings or 2 for savings"))
if self.opt == 1:
print ("Checkings Account ")
m1.userInputForChecking()
elif self.opt == 2:
m1.userInputForSaving()
else:
print("Invalid selection")
def saveToFile(self):
if self.opt == 1:
file= open("checkingAccouunt.txt", "w")
var= str(self.balance)
file.write(var)
print("balance has been written to checkings account file")
elif self.opt == 2:
file = open ("savingsAccount.txt", "w")
var=str(self.balance)
file.write("Current balance for users savings account", var)
print("balance has been writte n to savings file")
def main():
myObjectOne= ATM()
myObjectOne.checkingAccountFile()
myObjectOne.savingsAccountFile()
myObjectOne.chooseAccount()
myObjectOne.saveToFile()
main()
679.0
Which Account do you want to do a trasnaction on? Press 1 for checkings or 2 for savingsTraceback (most recent call last):
File "<pyshell#237>", line 1, in <module>
main()
File "<pyshell#236>", line 5, in main
myObjectOne.chooseAccount()
File "<pyshell#233>", line 99, in chooseAccount
self.opt= int(input("Which Account do you want to do a trasnaction on? Press 1 for checkings or 2 for savings"))
ValueError: invalid literal for int() with base 10: ' self.file.close()'