Advertisement
Gromov

Untitled

Oct 3rd, 2020
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. class Items:
  2.     __name: str
  3.     __code: int
  4.     __price: int
  5.  
  6.     #constr
  7.  
  8.     def __init__(self, name, code, price):
  9.         self.__name = name
  10.         self.__code = code
  11.         self.__price = price
  12.  
  13.     # get methods
  14.  
  15.     def get_name(self):
  16.         return self.__name
  17.  
  18.     def get_code(self):
  19.         return self.__code
  20.  
  21.     def get_price(self):
  22.         return self.__price
  23.  
  24.     # set methods
  25.  
  26.     def set_name(self, name):
  27.         self.__name = name
  28.  
  29.     def set_code(self, code):
  30.         self.__code = code
  31.  
  32.     def set_price(self, price):
  33.         self.__price = price
  34.  
  35.     # price from eur to usd
  36.  
  37.     def convert_price_to_usd(self):
  38.         return round(self.__price * 1.17, 2)
  39.  
  40. # MAIN
  41.  
  42.  
  43. the_great_database = []
  44. check = True
  45.  
  46. while check:
  47.  
  48.     menu = 0
  49.     while 1 > menu and menu < 4:
  50.         print("\n1)  Add item\n2)  Show all items\n3)  Find item via code\n4)  Exit")
  51.         menu = int(input("Make your choice: "))
  52.  
  53.     if menu == 1:
  54.         print("\nAdd item")
  55.         name = input("Item name: ")
  56.         code = int(input("Item Code: "))
  57.         price = float(input("Enter price: "))
  58.         the_great_database.append(Items(name, code, price))
  59.  
  60.     if menu == 2:
  61.         print("\nShow all items:")
  62.         for id in the_great_database:
  63.             print("Item name: " + id.get_name() + ", Item code: " + str(id.get_code()) + ", Price in USD: " + str(id.convert_price_to_usd()))
  64.         input("\nPress any key to continue.")
  65.  
  66.  
  67.     if menu == 3:
  68.         find = True
  69.         icode = int(input("Enter code: "))
  70.         for id in the_great_database:
  71.             if icode == id.get_code():
  72.                 print("\nItem name: " + id.get_name() + ", Item code: " + str(id.get_code()) + ", Price in USD: " + str(id.convert_price_to_usd()))
  73.                 find = False
  74.         if find:
  75.             input("Item not found.\nPress any key to continue.\n")
  76.  
  77.  
  78.     if menu == 4:
  79.         print("\nGoodbye!")
  80.         check = False
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement