· 4 years ago · Apr 23, 2021, 01:50 PM
1#
2# import random
3# import sqlite3
4#
5# con = sqlite3.connect('card.s3db')
6# cur = con.cursor()
7#
8# cur.execute("CREATE TABLE IF NOT EXISTS card (id INTEGER PRIMARY KEY AUTOINCREMENT,number TEXT,pin TEXT,balance INTEGER DEFAULT 0)")
9#
10#
11# class BankingSystem:
12# def __init__(self):
13# self.cards = {}
14# self.card_number = None
15# self.pin = None
16# self.balance = 0
17#
18# def menu(self):
19# print('1. Create an account')
20# print('2. Log into account')
21# print('0. Exit')
22# menu_choice = int(input())
23# if menu_choice == 1:
24# BankingSystem.account_create(self)
25# elif menu_choice == 2:
26# BankingSystem.login(self)
27# elif menu_choice == 0:
28# print('Bye!')
29# quit()
30#
31# def account_create(self):
32# id = str(random.randint(100000000, 999999999))
33# strip_lista = []
34#
35# for num in id:
36# strip_lista.append(int(num))
37#
38# strip_lista[0] = strip_lista[0] * 2
39# strip_lista[2] = strip_lista[2] * 2
40# strip_lista[4] = strip_lista[4] * 2
41# strip_lista[6] = strip_lista[6] * 2
42# strip_lista[8] = strip_lista[8] * 2
43#
44# for e in range(0, len(strip_lista)):
45# if strip_lista[e] > 9:
46# strip_lista[e] = strip_lista[e] - 9
47#
48# suma = (sum(strip_lista)) + 8
49# last_digit = 0
50# if (suma % 10) == 0:
51# last_digit = 0
52# else:
53# last_digit = 10 - (suma % 10)
54#
55# full_id = []
56# for c in id:
57# full_id.append(c)
58#
59# full_id.append(last_digit)
60#
61# for d in range(0, len(full_id)):
62# full_id[d] = str(full_id[d])
63#
64# full_id_str = ''.join(full_id)
65#
66# self.card_number = '400000' + full_id_str
67#
68# self.pin = random.randint(1000, 9999)
69# self.cards[int(self.card_number)] = self.pin
70# cur.execute("INSERT INTO card(number,pin) VALUES (?,?)", (self.card_number, self.pin,))
71# con.commit()
72# print(f"""Your card has been created
73# Your card number:
74# {self.card_number}
75# Your card PIN:
76# {self.pin}""")
77# # # print(self.cards)
78# # cur.execute("SELECT number,pin FROM card WHERE number=?", (self.card_number,))
79# # record = cur.fetchall()
80# # print(record[0][0])
81# # print(record[0][1])
82# BankingSystem.menu(self)
83#
84# def login(self):
85# card_n_given = int(input("Enter your card number:"))
86# pin_given = int(input('Enter your PIN:'))
87# cur.execute("SELECT number,pin FROM card WHERE number=?", (card_n_given,))
88# record = cur.fetchall()
89# print(record[0][0])
90# print(record[0][1])
91# if int(card_n_given) == int(record[0][0]):
92# if int(pin_given) == int(record[0][1]):
93# print('You have successfully logged in!')
94# BankingSystem.account_menu(self)
95# else:
96# print('Wrong card number or PIN!')
97# BankingSystem.menu(self)
98# else:
99# print('Wrong card number or PIN!')
100# BankingSystem.menu(self)
101#
102# def account_menu(self):
103# print("""1. Balance
104# 2. Log out
105# 0. Exit""")
106# account_menu_choice = int(input())
107# if account_menu_choice == 1:
108# BankingSystem.account_balance(self)
109# elif account_menu_choice == 2:
110# print('You have successfully logged out!')
111# BankingSystem.menu(self)
112# elif account_menu_choice == 0:
113# print('Bye!')
114# quit()
115#
116# def account_balance(self, card_n_given):
117# balance_db = cur.execute("SELECT balance FROM card WHERE number=?", (card_n_given,))
118# print(f'Balance: {balance_db}$')
119#
120#
121# def show_users(self):
122# print(self.cards)
123#
124#
125# u1 = BankingSystem()
126# u1.menu()
127# u1.show_users()