Although everything is right the input crash the code

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.





New contributor

no u is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật