Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getNumberFromUser(text, minValue, maxValue):
- number = None
- while(number == None):
- try:
- number = int(input(text))
- except ValueError:
- pass
- if number == None or number < minValue or number > maxValue:
- print("Некорректный ввод. Повторите.")
- number = None
- return number
- def waitForAnyButton():
- input("Нажмите любую клавишу чтобы выйти в меню...")
- class UserProfile:
- def __init__(self, name, money, business):
- self.__name = name
- self.__money = money
- self.__business = business
- def changeName(self, newName):
- self.__name = newName
- def addMoney(self, moneyToAdd):
- self.__money += moneyToAdd
- def changeBusiness(self, newBusiness):
- self.__business = newBusiness
- def __str__(self):
- return f"Имя: {self.__name}\nБаланс: {self.__money}\nБизнес: {self.__business}"
- class Menu:
- def __init__(self, menuList):
- self.__menuList = menuList
- self.__lenght = len(menuList)
- if(self.__lenght == 0):
- raise ValueError("Список должен содержать хотя бы один элемент!")
- def start(self):
- while True:
- print("Меню:")
- self.__printMenu()
- actionNumber = getNumberFromUser("Выберите пункт меню >>> ", 0, self.__lenght)
- if actionNumber == self.__lenght:
- break
- (self.__menuList[actionNumber]["action"])()
- def __printMenu(self):
- i = 0
- for i in range(0, self.__lenght):
- print(i, ")", self.__menuList[i]["title"])
- i += 1
- print(i, ") Выход")
- def businessListAction():
- print("Список бизнесов")
- waitForAnyButton()
- def doWorkAction():
- print("Работа")
- waitForAnyButton()
- name = input("Введите ваше имя: ")
- profile = UserProfile(name, 500, None)
- print("Ваш профиль:", profile, sep="\n")
- menu = Menu([{"title": "Список бизнесов", "action": businessListAction}, {"title": "Работать", "action": doWorkAction}])
- menu.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement