Advertisement
jimMoonrock

Card_anatomy

May 6th, 2021
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.40 KB | None | 0 0
  1. """
  2. self.information_for_database_database = 0
  3. d = self.information_for_database_database.fetchone()
  4. self.information_for_database_database = self.conn.execute("SELECT * FROM card")
  5. """
  6.  
  7. import random
  8. import sqlite3 as sl
  9.  
  10. class CardAnatomy:
  11.     def __init__(self):
  12.         self.__accounts = {}
  13.         self.__converted_list_of_numbers = []
  14.         self.__last_digit_card = 0
  15.         self.__card_number_sum = 0
  16.         self.choice = 0
  17.         self.__balance = 0
  18.         self.exit_point = False
  19.         self.__function_selection = 0
  20.         self.conn = sl.connect('card.s3db')
  21.         self.conn.execute("""
  22. CREATE TABLE IF NOT EXISTS card
  23. (
  24.    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  25.    number TEXT,
  26.    pin TEXT,
  27.    balance INTEGER DEFAULT 0
  28. );
  29.                        """)
  30.  
  31.  
  32.     def main_menu(self):
  33.         print("""
  34. 1. Create an account
  35. 2. Log into account
  36. 0. Exit""")
  37.         self.choice = int(input(""))
  38.         return self.user_choice()
  39.  
  40.  
  41.     def __create_card(self):
  42.         while True:
  43.             random.seed(random.randint(0, 5000))
  44.             card = 4000000000000000 + random.randint(0000000000, 9999999999)
  45.             pin = (random.randint(0, 9999))
  46.             pin = str(pin).zfill(4)
  47.  
  48.             self.__converted_list_of_numbers = list(map(int, list(str(card))))[::-1]
  49.             self.__last_digit_card, self.__card_number_sum = 0, 0
  50.  
  51.             for num in range(0, len(self.__converted_list_of_numbers)):
  52.                 if not num == 0:
  53.                     if num % 2 != 0:
  54.                         self.__card_number_sum += self.__converted_list_of_numbers[num] * 2 - 9 \
  55.                             if self.__converted_list_of_numbers[num] * 2 > 9 else\
  56.                             self.__converted_list_of_numbers[num] * 2
  57.                     else:
  58.                         self.__card_number_sum += self.__converted_list_of_numbers[num]
  59.                 else:
  60.                     self.__last_digit_card = self.__converted_list_of_numbers[num]
  61.  
  62.             if (self.__card_number_sum + self.__last_digit_card) % 10 == 0:
  63.                 self.conn.execute('INSERT INTO card (number, pin) values( ?, ?)', (str(card), pin))
  64.                 self.__accounts[str(card)] = pin
  65.                 #print(self.__accounts)
  66.                 print(f"""
  67. Your card has been created
  68. Your card number:
  69. {card}
  70. Your card PIN:
  71. {pin}""")
  72.                 return self.main_menu()
  73.             else:
  74.                 continue
  75.  
  76.  
  77.  
  78.     def authorization(self):
  79.         for _ in iter(int, 1):
  80.             check_login = input("""
  81. Enter your card number:
  82. """)
  83.             check_pin = input("""Enter your PIN:
  84. """)
  85.             if check_login.isdigit() and check_pin.isdigit():
  86.                 #check_login = int(check_login)
  87.                 #check_pin = int(check_pin)
  88.                 if self.__accounts.get(check_login) == check_pin:
  89.                     print("""
  90. You have successfully logged in!""")
  91.                     self.__function_selection = self.user_account()
  92.                 else:
  93.                     print("""
  94. Wrong card number or PIN!""")
  95.                     self.__function_selection = self.main_menu()
  96.                 return self.__function_selection
  97.             else:
  98.                 continue
  99.  
  100.  
  101.     def user_account(self):
  102.         while not self.exit_point:
  103.             print("""
  104. 1. Balance
  105. 2. Log out
  106. 0. Exit""")
  107.             self.choice = int(input(" "))
  108.             if self.choice == 1:
  109.                 print(f"""
  110. Balance: {self.__balance}""")
  111.                 continue
  112.             elif self.choice == 2:
  113.                 self.__function_selection = self.main_menu()
  114.             elif self.choice == 0:
  115.                 self.exit_point = True
  116.                 self.__function_selection = self.exit_s_db()
  117.         return self.__function_selection
  118.  
  119.  
  120.     def user_choice(self):
  121.         while not self.exit_point and self.choice in [0, 1, 2]:
  122.             if self.choice == 1:
  123.                 self.__function_selection = self.__create_card()
  124.             elif self.choice == 2:
  125.                 self.__function_selection = self.authorization()
  126.             elif self.choice == 0:
  127.                 self.exit_point = True
  128.                 self.__function_selection = self.exit_s_db()
  129.         return self.__function_selection
  130.  
  131.  
  132.     def exit_s_db(self):
  133.         self.conn.commit()
  134.         self.conn.close()
  135.         return "Bye!"
  136.  
  137.  
  138. ron = CardAnatomy()
  139. print(ron.main_menu())
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement