Advertisement
naren_paste

While Conditions

Nov 29th, 2023
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | Source Code | 0 0
  1. ##### User id and password setup #####
  2. correct_user_id = "your_username"
  3. correct_password = "your_password"
  4.  
  5. attempts = 0
  6. max_attempts = 3
  7.  
  8. while attempts < max_attempts:
  9.     # Get user input
  10.     user_id = input("Enter your user id: ")
  11.     password = input("Enter your password: ")
  12.  
  13.     # Check user id and password
  14.     if user_id == correct_user_id and password == correct_password:
  15.         print("Login successful!")
  16.         break
  17.     else:
  18.         attempts += 1
  19.         print(f"Invalid user id or password. Attempts left: {max_attempts - attempts}")
  20.  
  21. print("Too many incorrect attempts. Exiting.")
  22.  
  23.  
  24. ##### Initialize an empty list for the to-do items #####
  25. to_do_list = []
  26.  
  27. while True:
  28.     # Get user input
  29.     task = input("Enter a to-do item (or 'End Session' to finish): ")
  30.  
  31.     # Check for end condition
  32.     if task.lower() == "end session":
  33.         break
  34.  
  35.     # Add the task to the to-do list
  36.     to_do_list.append(task)
  37.  
  38. # Print consolidated to-do list
  39. print("\nConsolidated To-Do List:")
  40. for index, item in enumerate(to_do_list, start=1):
  41.     print(f"{index}. {item}")
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement