-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.

2
  • 1
    = is an assignment operator which can't be used in while loop, it needs a boolean condition Commented Jul 22, 2017 at 7:25
  • 1
    python is not a C language to assign values to variables in condition Commented Jul 22, 2017 at 7:27

3 Answers 3

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)
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

1

Use this code

while 1:
    print(input())

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.