##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 10\10.1468 - No Title.py
# Description: No Title
##############################################################################
class Menu:
def __init__(self):
self.options =[["Exit", None]]
def add_option(self, name, function):
self.options.append([name, function])
def display(self):
print("====")
print("Menu")
print("====\n")
for i, option in enumerate(self.options):
print(f"[{i}] - {option[0]}")
print()
def execute(self):
while True:
self.display()
choice = valid_integer_range("Choose an option: ",
0, len(self.options) -1)
if choice == 0:
break
self.options[choice][1]()