init
This commit is contained in:
commit
40c46ea6d2
113
main.py
Normal file
113
main.py
Normal file
@ -0,0 +1,113 @@
|
||||
import random, string
|
||||
users = []
|
||||
|
||||
class User:
|
||||
def __init__(self, pin, money):
|
||||
self.id = len(users) + 1
|
||||
self.pin = pin
|
||||
self.money = money
|
||||
self.transfer = False
|
||||
|
||||
def getMoney(self):
|
||||
print(self.money)
|
||||
|
||||
def withdrawMoney(self, amount):
|
||||
if amount <= self.money:
|
||||
self.money -= amount
|
||||
print("Wyplacono:", amount)
|
||||
else:
|
||||
print("Brak wystarczajacej ilosci srodkow")
|
||||
|
||||
def buyCode(self):
|
||||
if self.money >= 50:
|
||||
self.money = self.money - 50
|
||||
code = self.generateCode()
|
||||
print("Twoj kod:", code)
|
||||
else:
|
||||
print("Za malo pieniedzy")
|
||||
|
||||
def transferMoney(self, amount, user): #mozna przelac pieniadze samemu sobie
|
||||
if self.transfer == True:
|
||||
if user.transfer == True:
|
||||
self.money -= amount
|
||||
user.money += amount
|
||||
print("Wykonano przelew na:", amount)
|
||||
else:
|
||||
print("Uzytkownik do ktorego chcesz wyslac pieniadze, nie zezwolil na wykonywanie przelewow")
|
||||
else:
|
||||
print("Nie zezwoliles na wykonywanie przelewow")
|
||||
|
||||
def allowTransfer(self):
|
||||
self.transfer = True
|
||||
print("Zezwolono na wykonywanie przelewow")
|
||||
|
||||
def generateCode(self):
|
||||
pool = string.ascii_letters + string.digits
|
||||
code = ''
|
||||
for i in range(9):
|
||||
code += random.choice(pool)
|
||||
return code
|
||||
|
||||
user1 = User(1234, 500)
|
||||
users.append(user1)
|
||||
user2 = User(2222, 0)
|
||||
#user2.allowTransfer()
|
||||
users.append(user2)
|
||||
|
||||
def login():
|
||||
print("Podaj numer karty:")
|
||||
nr = int(input()) - 1
|
||||
print("Podaj numer PIN:")
|
||||
pin = int(input())
|
||||
if users[nr].pin == pin:
|
||||
print("Zalogowano\n")
|
||||
print("Witaj w Bankomacie!\n")
|
||||
return nr
|
||||
else:
|
||||
print("Nieprawidlowe dane\n")
|
||||
|
||||
user = None
|
||||
run = True
|
||||
|
||||
while(run == True):
|
||||
if user == None:
|
||||
user = login()
|
||||
else:
|
||||
|
||||
print("\nWybierz jedna z opcji:")
|
||||
print("1.Sprawdz stan konta")
|
||||
print("2.Wyplac pieniadze")
|
||||
print("3.Kup kod pre-paid")
|
||||
print("4.Wykonaj przelew")
|
||||
print("5.Zezwol na wykonywanie przelewow")
|
||||
print("9.Wyjdz")
|
||||
|
||||
key = int(input())
|
||||
|
||||
if key == 1:
|
||||
users[user].getMoney()
|
||||
elif key == 2:
|
||||
print("Podaj ilosc pieniedzy")
|
||||
amount = int(input())
|
||||
users[user].withdrawMoney(amount)
|
||||
elif key == 3:
|
||||
users[user].buyCode()
|
||||
elif key == 4:
|
||||
print("Podaj ilosc pieniedzy")
|
||||
amount = int(input())
|
||||
print("Podaj numer uzytkownika")
|
||||
nr = int(input()) - 1
|
||||
if nr == user:
|
||||
print("Nie mozesz wykonac przelewu do samego siebie")
|
||||
else:
|
||||
users[user].transferMoney(amount, users[nr])
|
||||
elif key == 5:
|
||||
users[user].allowTransfer()
|
||||
elif key == 9:
|
||||
run = False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user