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 -:
- Run the program
- select 1 to set pin and set the pin - 1234
- Run the Program
- 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()
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.