Here's what my task is:
Dependant on the "Logged In" user, they'll have different access rights and will see different menus.
I have tried using the .get()
function.
choices = {1: "| Student Details", 2: "| Student Grades", 3: "| Finance", 4:"| Staff Details", 5:"| Staff Payments"}
print(choices.get(1))
print(choices.get(4))
GIVEN OUTPUT >>
| Student Details
| Staff Details
But it will look very inefficient with all the Access Rights. Some access rights have access to different menus e.g (Access Level 1 = Menu 1 and Menu 4). So I cannot just use a for
loop to print all menus like so.
for option,num in choices.items():
print(option,num)
I've also attempted using the itemgetter() function which is available in the operator module, but I was unable of figuring out how to: 1. Print the outcome in lines, 2. Numerate the outcome in order (1,2,3)
choices = {1: "|Student Details", 2: "| Student Grades", 3: "| Finance", 4:"| Staff Details", 5:"| Staff Payments"}
print(itemgetter(3,5)(choices))
GIVEN OUTPUT >>
('| Finance', '| Staff Payments')
REQUIRED OUTPUT >>
1 | Finance
2 | Staff Payments
Here's an example of the inefficient code I have at the moment:
if user_name == "Mike":
print("-Managing Menu-")
print("1 | Staff Payments. ")
print("2 | Finance. ")
option = int(input("Option Choice (1-2): "))
while option not in range(1,2):
option = int(input("Option Choice (1-2): "))
if option == 1:
print("Welcome to Staff Payments")
elif option == 2:
print("Welcome to Finance.")
else:
print("Error.")
I'd really appreciate any feedback and help with this task.