actual
This commit is contained in:
parent
d7e39ea89c
commit
1253953bf6
61
ATM.py
Normal file
61
ATM.py
Normal file
@ -0,0 +1,61 @@
|
||||
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
|
30
Card.py
Normal file
30
Card.py
Normal file
@ -0,0 +1,30 @@
|
||||
class Card:
|
||||
|
||||
def __init__(self, id_card, pin, money):
|
||||
self.id_card = id_card
|
||||
self.pin = pin
|
||||
self.money = money
|
||||
|
||||
def transfer_minus(self, amount):
|
||||
if amount > self.money:
|
||||
return False
|
||||
else:
|
||||
self.money = self.money - amount
|
||||
return True
|
||||
|
||||
def transfer_plus(self, amount):
|
||||
self.money = self.money + amount
|
||||
|
||||
def withdraw_money(self, amount):
|
||||
if amount > self.money:
|
||||
return print("You don't have enough money on your card")
|
||||
else:
|
||||
self.money = self.money - amount
|
||||
return print("Take your money")
|
||||
|
||||
def top_up(self, amount):
|
||||
self.money = self.money + amount
|
||||
return print("Operation success")
|
||||
|
||||
def balance_info(self):
|
||||
return print("Your balance is:", self.money)
|
Loading…
Reference in New Issue
Block a user