I am learning python. I tried to the following code but it did not work. How can I print inputs from a user repeatedly in python?
while ( value = input() ):
print(value)
Thank you very much.
I am learning python. I tried to the following code but it did not work. How can I print inputs from a user repeatedly in python?
while ( value = input() ):
print(value)
Thank you very much.
while true
is an infinite loop, therefore it will always take an input and print the output. value
stores the value of a user input, and print
prints that value after. This will always repeat.
while True:
value = input()
print(value)
Use this code
while 1:
print(input())
If you want to stop taking inputs, use a break with or without condition.
Assignments within loops don't fly in python. Unlike other languages like C/Java, the assignment (=
) is not an operator with a return value.
You will need something along the lines of:
while True:
value = input()
print(value)