Advertisement
earlution

user_input_to_list.py

Oct 6th, 2023
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # Initialise an empty list to store user inputs
  2. user_inputs = []
  3.  
  4. while True:
  5.     # Capture user input
  6.     user_input = input("Enter a value (or 'exit' to quit): ")
  7.  
  8.     # Check if the user wants to exit
  9.     if user_input.lower() == "exit":
  10.         break  # Exit the loop if the user enters 'exit'
  11.    
  12.     # Add the user input to the list
  13.     user_inputs.append(user_input)
  14.  
  15. # Display the list of user inputs
  16. print("User inputs:")
  17. for item in user_inputs:
  18.     print(item)
  19.  
Tags: python list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement