-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,217
  • 4
  • 22
  • 32

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
  • 414
  • 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
  • 16,526
  • 5
  • 37
  • 65
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
  • 379,657
  • 97
  • 704
  • 746