Pythonic
Pythonic

Reputation: 173

Input() to Allow <Enter Key> to Insert New Line Instead Of Returning Out of the Code in Python 3.x

I am new to Python so please explain any code you write!

I want an input() to terminate after 1 blank line to allow for more than one line.

For example, if I press Enter while using input(), I want it to go onto the next line, but if I press Enter again, it returns out of the program.

Upvotes: 0

Views: 1367

Answers (1)

Raydel Miranda
Raydel Miranda

Reputation: 14360

Try this:

quit = False

while not quit:
    d = input()
    print(d)
    if d == '': quit = True

or

while True:
    d = input()
    if d == '': break
    print(d)

Upvotes: 1

Related Questions