62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
|
class ATM:
|
||
|
|
||
|
def __init__(self, cards):
|
||
|
self.cards = cards
|
||
|
|
||
|
def enter_card(self):
|
||
|
id_card = int(input('Please enter you card:'))
|
||
|
current_card = self.check_availability(id_card)
|
||
|
if not current_card:
|
||
|
print("We don't have your card in our base")
|
||
|
return False
|
||
|
return self.enter_pin(current_card)
|
||
|
|
||
|
def check_availability(self, id_card):
|
||
|
for i in self.cards:
|
||
|
if i.id_card == id_card:
|
||
|
return i
|
||
|
return False
|
||
|
|
||
|
def enter_pin(self, card):
|
||
|
pin = int(input('0 - to leave\n'
|
||
|
'Please enter you PIN:'))
|
||
|
if pin == 0:
|
||
|
return False
|
||
|
else:
|
||
|
if card.pin == pin:
|
||
|
return self.atm_menu(card)
|
||
|
else:
|
||
|
print('Wrong PIN')
|
||
|
return self.enter_pin(card)
|
||
|
|
||
|
def atm_menu(self, card):
|
||
|
command = 1
|
||
|
while command != 0:
|
||
|
print('1 - Check your balance\n'
|
||
|
'2 - Withdraw money\n'
|
||
|
'3 - Top up you card\n'
|
||
|
'4 - Transfer money\n'
|
||
|
'0 - To leave'
|
||
|
)
|
||
|
command = int(input('Type:'))
|
||
|
if command == 1:
|
||
|
card.balance_info()
|
||
|
if command == 2:
|
||
|
amount = int(input('How much money you want to withdraw:'))
|
||
|
card.withdraw_money(amount)
|
||
|
if command == 3:
|
||
|
amount = int(input('Put money in:'))
|
||
|
card.top_up(amount)
|
||
|
if command == 4:
|
||
|
money_taker_id = int(input('Type a card_id you want to transfer money:'))
|
||
|
money_taker_card = self.check_availability(money_taker_id)
|
||
|
if money_taker_card:
|
||
|
amount = int(input('How much money you want to transfer:'))
|
||
|
if card.transfer_minus(amount):
|
||
|
money_taker_card.transfer_plus(amount)
|
||
|
else:
|
||
|
print("You don't have enough money to transfer)")
|
||
|
else:
|
||
|
print("We don't have this user in our base")
|
||
|
return True
|