You have to use raw_input (input tries to run the input as a python expression and this is not what you want) and fix the indentation problem.

name = "not_aneta"

while name!= "aneta":
    name = raw_input("What is my name? ")

    if name == "aneta":
        print "You guessed my name!"
Answer from Avión on Stack Overflow
🌐
Learner
ahmedgouda.hashnode.dev › user-input-and-while-loops-in-python
User Input and While Loops in Python - Learner
May 8, 2022 - We can make program runs as long as the user wants by putting most of the code inside a while loop. We’ll define a quit value and then keep the program running as long as the user has not entered the quit value. prompt = "\nTell me something, and I will repeat it back to you:" prompt += "\nEnter 'quit' to end the program. " message = "" while message != 'quit': message = input(prompt) if message != 'quit': print(message)
Discussions

Using a while loop to ask the user (Y/N) ?
You can stay in the loop until they provide the answer you want and then break when they do. while True: answer = input('y or n: ').lower() if answer in ['y','n']: break More on reddit.com
🌐 r/learnpython
6
4
October 31, 2023
python while loop user input - Stack Overflow
Write a program that keeps asking the user for numbers until they enter a non-number. This is what I have now, it seems I have created an infinite loop. i = 0 count = 0 while i != (int): i = ... More on stackoverflow.com
🌐 stackoverflow.com
python - User input and while loop - Stack Overflow
I'm trying to write a Python program where it asks user to make selection using 1, 2 or 3. If user doesn't enter those, it prompts user to enter only those numbers. Once the user enters 1, 2 or 3,... More on stackoverflow.com
🌐 stackoverflow.com
How do you loop until correct input is given?
First find what loop you need. If the number of iterations is known beforehand then for. If not known then while. Then find how to draw a random number. Test in the python interpreter. Then find how to use the input function. Test in tje python interpreter. Brick by brick you will build you way ;) More on reddit.com
🌐 r/learnpython
33
29
February 25, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-user-input-in-loop-using-python
Get User Input in Loop using Python - GeeksforGeeks
July 23, 2025 - In Python, for and while loops ... repeatedly. 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....
🌐
Stack Abuse
stackabuse.com › bytes › using-for-and-while-loops-for-user-input-in-python
Using For and While Loops for User Input in Python
August 18, 2023 - In the above code, we're using a while loop to continuously ask the user for input. The loop will only terminate when the user enters the word "quit". Here's what the output might look like: Please enter some text: Hello You entered: Hello Please enter some text: quit · Note: Remember that the input() function in Python always returns a string.
🌐
Reddit
reddit.com › r/learnpython › using a while loop to ask the user (y/n) ?
r/learnpython on Reddit: Using a while loop to ask the user (Y/N) ?
October 31, 2023 -

So I have a program that calculates compound interest, and now I need to add a question at the end of my program that asks the user if they would like to run the program again, if they answer with Y or y the program will restart to the beginning, if they answer “N” or “n” the program is over. And if they answer with anything other than y or n it should repeat the question until the user finally enters y or n

What I have so far:

I have my entire program in a while loop and was able to get it to reset while Var == Y or y. But I can’t get it to repeat the question if the user answers with let’s say “q” or “618” or “L”. Does anyone know how to do something like this, please let me know… thank you

🌐
Introtopython
introtopython.org › while_input.html
While Loops and Input
You can 'seed' the list with # some predefined values if you like. names = [] # Set new_name to something other than 'quit'. new_name = '' # Start a loop that will run until the user enters 'quit'. while new_name != 'quit': # Ask the user for a name. new_name = input("Please tell me someone I should know, or enter 'quit': ") # Add the new name to our list.
🌐
Mimo
mimo.org › glossary › python › while-loop
Master Python While Loops: A Comprehensive Guide
This makes for an intuitive and user-friendly interface. ... choice = "" while choice != "Q" : print ( "1: Option 1" ) print ( "2: Option 2" ) print ( "Q: Quit" ) choice = input ( "Select an option: " ) # Process the choice · Within monitoring applications, a while loop might check the system status of a server.
Find elsewhere
🌐
Webscale
section.io › home › blog
Webscale Blog: Insights on AI & Commerce | Webscale
May 29, 2026 - Ecommerce failures during peak traffic start before the outage. Slow pages, cache misses, and shopper refreshes cost revenue while dashboards still say the site is up.
🌐
AskPython
askpython.com › python › python-while-loop
Python while Loop - AskPython
April 19, 2026 - Use a while loop when you do not know how many iterations you need at the start. This happens with user input validation, reading until EOF, waiting for a condition to change, or implementing retry logic.
🌐
Delft Stack
delftstack.com › home › howto › python › python while loop user input
How to Get User Input in Python while Loop | Delft Stack
March 11, 2025 - This structure allows for a user-friendly experience, making it easy to interact with the program. In summary, using the input() function within a while loop in Python is a powerful way to handle user input dynamically.
🌐
Gishub
geohey.gishub.org › python › 07_user_input_while_loops
07 user input while loops - geohey
" message = "" # while message ... the loop, message is just an empty string, so Python enters the loop. At message = input(prompt), Python displays the prompt and waits for the user to enter their input....
🌐
Bobby Hadz
bobbyhadz.com › blog › python-for-loop-user-input
Using a For or While Loop to take user input in Python | bobbyhadz
Use the input() function to take user input. If the condition is met, break out of the while loop.
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-basics-part-1 › loops › while-loop › while-loops-for-user-input
Create an interactive while loop | Python Basics course
However, there are also situations when we don't know the exact number of iterations. Take a look: user_input = input('Please provide a number: ') while not user_input.isnumeric(): user_input = input('Not a number!
🌐
GitHub
github.com › leriomaggio › python-in-a-notebook › blob › master › 05 While Loops and User input.ipynb
python-in-a-notebook/05 While Loops and User input.ipynb at master · leriomaggio/python-in-a-notebook
"While loops are really useful because they let your program run until a user decides to quit the program. They set up an infinite loop that runs until the user does something to end the loop. This section also introduces the first way to get input from your program's users." ... "* In Python, also `while` loops are permitted, but `for` is the one you would see (and use) most of the time!"
Author: leriomaggio
🌐
Tech with Tim
techwithtim.net › tutorials › python-programming › beginner-python-tutorials › while-loops
Beginner Python Tutorial - While Loops
Here is a common example of when we would use a while loop: # When we want to keep asking the user for input until we get a certain value run = False while run: answer = input("What is 5 + 7") if answer == "12": print("Correct!") run = False else: print("Try Again...")
🌐
SQLPad
sqlpad.io › tutorial › python-while-loop
Python while loop | SQLPad
April 29, 2024 - Embedded systems that need to monitor sensors and respond to events without stopping. The most straightforward way to create an infinite loop in Python is to use a while statement with a condition that always evaluates to True.
🌐
Reddit
reddit.com › r/learnpython › how do you loop until correct input is given?
r/learnpython on Reddit: How do you loop until correct input is given?
February 25, 2022 -

I'm doing an assignment that requires I make a code that creates random numbers in a loop until I give a specific input. I just don't know how to get the loop to run while an input is requested. PLZ HELP!

EDIT:

To clarify the assignment:

Write a program that enters a number of positive integers.

The program ends when the user gives in a negative number.

a) Before the program ends, the largest number is printed.

b) Before the program ends, the smallest number is printed.

c) Before the program ends, the sum of the even numbers and the sum of the odd numbers are printed.

(I can do the a,b,c part no problem. It's the Program that creates the numbers i have problems with)

I asked my teacher what he meant by "a number of positive integers". He stated that the program should create numbers until the negative number is given.

EDIT 2:

I have concluded that I'm an idiot. It is the user who inputs the numbers. Thank you all for the help and not giving up with my dense skull :) (great community👍)

🌐
Python Forum
python-forum.io › thread-42755.html
User input with while loops
August 24, 2024 - Hi , Thanks for viewing, hope all is good. I'm trying to put together a rock paper scissors code and what i was trying to do as an improvement, was to to the user from inputting a non good input and only allowing the 3 inputs to play. On first wrong ...