0
class Atm:
    def __init__(self):
        self.pin = ""
        self.balance = 0
        
        
    def menu(self):
            ask = int(input("""

            Select from the menu
            1. Press 1 to set your pin
            2. Press 2 to deposit
            3. Press 3 to withdrawl
            4. Press 4 to check balance
            5. Press 5 to exit
        
            :  """))
            if ask == 1:
                self.create_pin()
            elif ask == 2:
                self.deposit()
            
    def create_pin(self):
        self.pin = input(" Set your pin : ")
        print(" Pin sucesfully set ")
    
    
    def deposit(self):
        print(self.pin)
        tmp = input(" Enter your pin : ")
        if tmp == self.pin:
            amount = float(input(" Enter your deposit amount  : "))
            self.balance = amount + self.balance
            print(" Amount Deposit sucessfully ")
        else:
            print(" Wrong Pin ")
            
                       
        
        

sbi = Atm()
sbi.menu()

Hello Everyone,

Here I am writing a very simple program for ATM machine. I already created a instance variable called self.pin and I assign a value inside it using " create_pin " method but when I am trying to use this variable inside method " deposit ", I am not able to access it and it always going inside else condition and getting output wrong pin.

step to reproduce -:

  1. Run the program
  2. select 1 to set pin and set the pin - 1234
  3. Run the Program
  4. select 2 to deposit and enter the pin - 1234 output -: wrong pin

expectation -: It should match the temp variable with pre set pin and if pin is correct, it should allow user to deposit the amount.

Problematic Method -: deposit()

2
  • Nothing is saved when you run the program twice. If you run sbi.menu() twice it will work. You will need to store your pin in a file or similar if you want to keep it over multiple file runs. Commented Nov 22, 2022 at 4:05
  • I added this small part in my code after your suggestion and it worked -: { sbi = Atm() while True: sbi.menu() } can I create a empty list variable in constructor and append the value directly inside it from other methods?? Thank you sooo much Commented Nov 22, 2022 at 4:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.