From 1253953bf698c2b1b373bc137989329c8aa4bcfe Mon Sep 17 00:00:00 2001 From: s464858 Date: Wed, 12 Oct 2022 17:44:48 +0200 Subject: [PATCH] actual --- ATM.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Card.py | 30 ++++++++++++++++++++++++++++ main.py | 8 ++++++++ 3 files changed, 99 insertions(+) create mode 100644 ATM.py create mode 100644 Card.py create mode 100644 main.py diff --git a/ATM.py b/ATM.py new file mode 100644 index 0000000..5487b3c --- /dev/null +++ b/ATM.py @@ -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 diff --git a/Card.py b/Card.py new file mode 100644 index 0000000..ce4c416 --- /dev/null +++ b/Card.py @@ -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) diff --git a/main.py b/main.py new file mode 100644 index 0000000..871a126 --- /dev/null +++ b/main.py @@ -0,0 +1,8 @@ +from Card import * +from ATM import * + +cards = [Card(1, 1234, 1000), Card(2, 1233, 500), Card(3, 1222, 100)] + +bankomat = ATM(cards) +while True: + bankomat.enter_card()