-2

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.

mora
  • 2,027
  • 3
  • 15
  • 30

3 Answers3

1

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)
13smith_oliver
  • 394
  • 6
  • 13
1

Use this code

while 1:
    print(input())

If you want to stop taking inputs, use a break with or without condition.

bigbounty
  • 14,834
  • 4
  • 27
  • 58
1

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)
cs95
  • 330,695
  • 80
  • 606
  • 657