Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.3 kB
13
Indexable
class Atm:
    # Constructor
    def __init__(self):
        self.__pin = ''
        self.__balance = 0
        self.__menu()
        
    #getter method
    def get_pin(self):
        return self.__pin

    #setter method
    def set_pin(self,new_pin):
        if type(new_pin) == str:
            self.__pin = new_pin
            print("New Pin set successfuly")
        else:
            print("Not allowed")
            
        
    
    def __menu(self):
        user_input = input('''
                Hello, how would you like to proceed?
                1.Enter 1 to create pin
                2.Enter 2 to deposit
                3.Enter 3 to withdraw
                4.Enter 4 to check balance
                5.Enter 5 to exit
''')
        if user_input == '1':
            #print("Create pin")
            self.create_pin()

        elif user_input == '2':
            #print("Deposit")
            self.deposit()

        elif user_input == '3':
            #print("Withdraw")
            self.withdraw()

        elif user_input == '4':
            #print("Check Balance")
            self.check_balance()

        else:
            print("Bye")

    def create_pin(self):
         self.__pin = input("Enter your Pin")
         print("Pin set successfully")

    def deposit(self):
         temp = input("Enter your pin")
         if temp == self.__pin:
             amount = int(input("enter the amount"))
             self.__balance = self.__balance + amount
             print("Deposit successfull")
         else:
             print("Invalid pin")
    def withdraw(self):
         temp = input("Enter your pin")
         if temp == self.__pin:
             amount = int(input("Enter the amount"))
             if amount <= self.__balance:
                 self.__balance = self.__balance - amount
                 print("Amount wihdrawn succefully")
             else:
                 ("Insufficient funds")
         else:
             print("Invalid pin")
    def check_balance(self):
         temp = input("Enter  your pin")
         if temp == self.__pin:
             print(self.__balance)
         else:
             print("Invalid pin")