Python ATM Simulation

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()'

Your code assumes the user will always return an integer, and will never just hit enter, the space bar, or enter random text. Whatever text they type in, is what input will return, and you pass that straight into int, even when it contains characters outside of 1234567890.

Ok but isn’t that what else clause is for though? I still dont get why every time I run the program it gives me that error

Can you post the error message that the above code generates please?

It’s fundamentally a design flaw. You’ve come up with a great little simulation that works for yourself, who knows to type in numerical input. But as soon as it came into contact with real users who just mashed the keyboard and pressed enter, it crashed.

        self.account= int(input("Which account do you want to transfer money to? Press 1 for checking or 2 for savings"))

Here, and elsewhere, your program assumes the user is an expert user, so simply was not designed to handle all the possible user inputs.

There are countless options in Python to help you fix this, not just the three else clauses. Although the else in conjunction with try isn’t a terrible idea.

But neither an else or any other Python language feature, isn’t an instant fix for the fundamental issue - lack of input checking and sanitisation, and/or a lack of error handling (either as retcodes or Exceptions).

Never use float in ATM. Decimal instead. Otherwise, the program will evaluate a wrong value in 0.1+0.2.