Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Items:
- __name: str
- __code: int
- __price: int
- #constr
- def __init__(self, name, code, price):
- self.__name = name
- self.__code = code
- self.__price = price
- # get methods
- def get_name(self):
- return self.__name
- def get_code(self):
- return self.__code
- def get_price(self):
- return self.__price
- # set methods
- def set_name(self, name):
- self.__name = name
- def set_code(self, code):
- self.__code = code
- def set_price(self, price):
- self.__price = price
- # price from eur to usd
- def convert_price_to_usd(self):
- return round(self.__price * 1.17, 2)
- # MAIN
- the_great_database = []
- check = True
- while check:
- menu = 0
- while 1 > menu and menu < 4:
- print("\n1) Add item\n2) Show all items\n3) Find item via code\n4) Exit")
- menu = int(input("Make your choice: "))
- if menu == 1:
- print("\nAdd item")
- name = input("Item name: ")
- code = int(input("Item Code: "))
- price = float(input("Enter price: "))
- the_great_database.append(Items(name, code, price))
- if menu == 2:
- print("\nShow all items:")
- for id in the_great_database:
- print("Item name: " + id.get_name() + ", Item code: " + str(id.get_code()) + ", Price in USD: " + str(id.convert_price_to_usd()))
- input("\nPress any key to continue.")
- if menu == 3:
- find = True
- icode = int(input("Enter code: "))
- for id in the_great_database:
- if icode == id.get_code():
- print("\nItem name: " + id.get_name() + ", Item code: " + str(id.get_code()) + ", Price in USD: " + str(id.convert_price_to_usd()))
- find = False
- if find:
- input("Item not found.\nPress any key to continue.\n")
- if menu == 4:
- print("\nGoodbye!")
- check = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement