EDIT: Seems like people doesen't understand the point... I have three diferent functions that can call one common function. How to back from that common function to right previous function depending of user role?
I have login function like this:
def login():
users = open('users.txt', 'r').readlines()
username = input("\nKorisnicko ime: ")
password = input("Lozinka: ")
for i in users:
users=i.strip("\n").split("|")
if (username == users[0] and password == users[1]):
print("\nDobrodosli: " + users[2].title(), users[3].title()+"\n" )
if users[4] == 'kupac':
buyer_menu()
elif users[4] == 'prodavac':
seller_menu()
elif users[4] == 'menadzer':
manager_menu()
And buyer, seller and manager functions like this:
def buyer_menu():
print("=== BUYER ===")
print("1. Search movie")
print("2. Search moive")
print("7. Logout")
print("8. Exit")
options = input("\nChoose option >>> ")
if options == '1':
search_movie()
elif options == '2':
search.search_movie()
...
elif options == '8':
print ("Predstava je otkazana. Nestalo struje.")
exit()
else:
print("Nepostojeca opcija!\n")
buyer_menu()
Seller.
def seller_menu():
print("=== SELLER ===")
print("1. Search movie")
print("2. Search ticket")
print("7. Back to main menu")
options = input("\nChoose option >>> ")
if options == '1':
search_movie()
elif options == '2':
search.search_movie()
elif options == '7':
main()
elif options == '8':
print ("Predstava je otkazana. Nestalo struje.")
exit()
else:
print("Nepostojeca opcija!\n")
buyer_menu()
Manager:
def manager_menu():
print("=== MANAGE ===")
print("1. Search movie")
print("2. Search users")
print("8. Exit")
options = input("\nChoose option >>> ")
if options == '1':
search_movie()
elif options == '2':
search.search_users()
elif options == '8':
print ("Predstava je otkazana. Nestalo struje.")
exit()
else:
print("Nepostojeca opcija!\n")
buyer_menu()
Ass you can see all trhee type of users have "Search movie" options, and function for that looks like this:
def search_movie():
print("\n1. Search movie title")
print("2. Search movie genre")
print("8. Back to main menu")
options = input("\nUnesite kriterijum za pretragu >>> ")
if options == '1':
search_movie_title()
elif options == '2':
search_movie_genre()
Now, if you see, problem is function for back to main menu....
For example: If I'm logged in as a buyer and I choose search movie option, but then I want to back to main menu, how to back on buyer_menu():
And so on fo other type of users... seller on seller_menu():
and manager on manager_menu():