your text
#This is all relevent code
logged_in_user = None
logged_in = False
def user():
global logged_in_user
try:
choose_login = int(input(‘Please specify type of user: n 1) Admin n 2) System Provider n 3) Guest n 4) Travelern’))
if choose_login == 1:
logged_in_user = 'Admin'
print(f'Logged in as {logged_in_user}')
main()
elif choose_login == 2:
logged_in_user = 'System Provider'
print(f'Logged in as {logged_in_user}')
menu()
elif choose_login == 3:
logged_in_user = 'Guest'
print(f'Logged in as {logged_in_user}')
elif choose_login == 4:
logged_in_user = 'Traveler'
print(f'Logged in as {logged_in_user}')
elif choose_login == 5:
print(users)
else:
raise ValueError('Invalid selection. Please choose a number between 1 and 4.')
except ValueError as e:
print(e)
user()
def login(username, password):
global logged_in_user, logged_in
for user_info in users.values():
if user_info[‘username’] == username and user_info[‘password’] == password:
logged_in_user = username
logged_in = True
return True
return False
def logout():
global logged_in_user, logged_in
logged_in_user = None
logged_in = False
print(“Logged out successfully.”)
def add_user(role, username):
if username not in users:
password = input(f”Enter password for {username}: “)
users[username] = {“username”: username, “password”: password, “Role”: role.capitalize(), ‘Blocked’: False}
print(f”User {username} has been added as a {role}.”)
else:
print(f”User {username} already exists.”)
def main():
global logged_in
login_attempts = 0 # Initialize login attempts counter
max_attempts = 3 # Maximum allowed login attempts
while True:
try:
if not logged_in:
if login_attempts >= max_attempts:
print(“Maximum login attempts exceeded. Logging out.”)
logout()
break
username = input(“Enter username: “)
password = input(“Enter password: “)
login_result = login(username, password)
if not login_result:
login_attempts += 1
print(“Invalid username or password. Please try again.”)
continue
else:
login_attempts = 0
else:
user_role = users[logged_in_user][‘Role’]
if user_role == ‘Admin’:
print(f’Welcome {logged_in_user}!’)
print(“n1. Logout”)
print(“2. Block Traveller”)
print(“3. Add Merchant”)
print(“4. Block Merchant”)
print(“5. Update Promotion”)
print(“6. Provide Trip Recommendation”)
print(“7. Switch to User Menu”)
action = input(“Choose an action: “)
if action == ‘1’:
logout()
break
elif action == ‘2’:
username = input(“Enter traveller username to block: “)
block_user(‘Traveller’, username)
elif action == ‘3’:
username = input(“Enter merchant username to add: “)
add_user(‘System Provider’, username)
elif action == ‘4’:
username = input(“Enter merchant username to block: “)
block_user(‘System Provider’, username)
elif action == ‘5’:
promotion = input(“Enter new promotion: “)
update_promotion(promotion)
elif action == ‘6’:
recommendation = input(“Enter trip recommendation: “)
provide_trip_recommendation(recommendation)
elif action == ‘7’:
logout()
user()
return
else:
print(“Invalid action.”)
except Exception as e:
print(f”An error occurred: {e}”)users = {
“merchant”: {“username”: “merchant”, “password”: “password”, “Role”: “System Provider”, ‘Blocked’: False},
“traveler”: {“username”: “traveler”, “password”: “password”, “Role”: “Traveler”, ‘Blocked’: False},
“omar”: {“username”: “omar”, “password”: “password”, “Role”: “System Provider”, ‘Blocked’: False},
“ahmed”: {“username”: “ahmed”, “password”: “password”, “Role”: “Traveler”, ‘Blocked’: False},
“admin”: {“username”: “admin”, “password”: “password”, “Role”: “Admin”, ‘Blocked’: False}
}
def menu():
global logged_in
login_attempts = 0 # Initialize login attempts counter
max_attempts = 3 # Maximum allowed login attempts
while True:
if not logged_in:
if login_attempts >= max_attempts:
print(“Maximum login attempts exceeded. Logging out.”)
logout()
break
username = input(“Enter username: “)
password = input(“Enter password: “)
login_result = login(username, password)
if not login_result:
login_attempts += 1
print(“Invalid username or password. Please try again.”)
return
else:
login_attempts = 0 # Reset login attempts counter on successful login
else:
user_role = users.get(logged_in_user, {}).get(‘Role’)
user_blocked = users.get(logged_in_user, {}).get(‘Blocked’, False)
if not user_blocked:
if user_role == ‘System Provider’:
print(f’Welcome {logged_in_user}!’)
print(“nMenu:”)
print(“1. Update product time”)
print(“2. Update product price”)
print(“3. Update product quantity”)
print(“4. View all products”)
print(“5. Logout”)
print(‘6. Switch to user menu’)
choice = input("Enter your choice: ")
if choice == "1":
product_id = input("Enter the Product ID you want to update: ")
if product_id in kl_trip_planner_data:
print(f"Current time for {product_id}: {kl_trip_planner_data[product_id]['Time']}")
new_time = input("Enter new time: ")
kl_trip_planner_data[product_id]["Time"] = new_time
print("Product time updated successfully.")
write_to_file()
else:
print("Product not found.")
elif choice == "2":
product_id = input("Enter the Product ID you want to update: ")
if product_id in kl_trip_planner_data:
try:
new_price = float(input("Enter the new price: "))
kl_trip_planner_data[product_id]["Price"] = new_price
print("Product price updated successfully.")
write_to_file()
except ValueError:
print("Invalid price. Please enter a valid number.")
else:
print("Product not found.")
elif choice == "3":
product_id = input("Enter the Product ID you want to update: ")
if product_id in kl_trip_planner_data:
try:
new_quantity = int(input("Enter the new quantity: "))
kl_trip_planner_data[product_id]["Quantity"] = new_quantity
print("Product quantity updated successfully.")
write_to_file()
except ValueError:
print("Invalid quantity. Please enter a valid number.")
else:
print("Product not found.")
elif choice == '4':
view()
elif choice == "5":
logout()
break
elif choice == "6":
logout()
user()
return
else:
print("Invalid choice. Please enter a number between 1 and 5.")
else:
print("You are blocked from accessing the menu.")
logout()
break
Start the program by calling the user function
user()
So im trying to make a simple appliacation for my school assignment where i have to make a trip planner and i have to create roles like admin , merchant , and traveler.so the admin has add function where he can add new merchants to access the merchant function. But everytime I try to sign with the new user the terminal freezes.
no u is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.