About 2,820,000 results
Open links in new tab
  1. loops - Python: How to keep repeating a program until a specific input

    There are two ways to do this. First is like this: inp = raw_input() # Get the input. if inp == "": # If it is a blank line... break # ...break the loop. The second is like this: inp = raw_input() # Get the input again. Note that if you are on Python 3.x, you will need to replace raw_input with input.

  2. Python capture user input while in loop executing other code?

    Jan 18, 2017 · What I'd like to do is be able to hit keyboard buttons, while the program is running, and then save and process that input (e.g. as a command to change some parameter) on the next start iteration of that loop.

  3. Get User Input in Loop using Python - GeeksforGeeks

    5 days ago · When it comes to user input, these loops can be used to prompt the user for input and process the input based on certain conditions. In this article, we will explore how to use for and while loops for user input in Python.

  4. How to Take Multiple Inputs Using Loop in Python

    Feb 22, 2024 · Take Multiple Inputs In Python Using While Loop. In this example, below code initializes an empty list called `inputs_list` to store user inputs. It then prompts the user to enter a value and uses a `while` loop to continuously take inputs until the user types 'exit'. Each entered value is appended to the `inputs_list`.

  5. How can you store user input within a loop without overwriting?

    Oct 29, 2015 · I'm having a user input info for a program and I'm having trouble storing information from user without it overwriting in a loop. My code as follows: total_circles = input("Enter the number of circles: ") for number in range(1, int(total_circles) + 1): circles = input("Enter the radius of circle {}: ".format(number)) circle_value = float(circles)

  6. Using a For or While Loop to take user input in Python

    Apr 9, 2024 · To use a for loop to take user input: Declare a new variable and initialize it to an empty list. Use the range() class to loop N times in a for loop. On each iteration, append the input value to the list. my_list.append(input('Enter a country: ')) print(my_list) The first example takes multiple string inputs from a user and appends them to a list.

  7. How to Get User Input in Python while Loop - Delft Stack

    Mar 11, 2025 · Learn how to get user input in Python while loops effectively. This guide covers using the input() function to gather data until a condition is met, implementing input validation, and creating menu-driven programs.

  8. 5 Best Ways to Take Multiple Inputs from User in Python

    Mar 11, 2024 · Method 1: Using a For Loop. One of the easiest ways to take multiple inputs in Python is by using a for loop. This allows us to iterate over a fixed number of inputs, prompting the user each time. The function specification for this method involves looping a set number of times and using the input() function within the loop to collect user data.

  9. How to Take Continuous Input in Python? - Python Guides

    Jun 18, 2023 · Python has a built-in function called input() which is used to take user input. Example: You can use loops, such as while loops, to keep taking input from the user until a certain condition is met. user_input = input("Enter something (or 'exit' to stop): ") if user_input == 'exit': break. print("You entered:", user_input)

  10. Using For and While Loops for User Input in Python - Stack Abuse

    Aug 18, 2023 · In this Byte, we will explore how to use for and while loops for user input in Python. User Input with For Loops. The for loop in Python is used to iterate over a sequence (such as a list, tuple, dictionary, string, or range) or other iterable objects. Iterating over a sequence is called traversal. Let's see how we can use a for loop to get ...

Refresh