ShyMike
ShyMike

Reputation: 5

python: Cant figure out how to make enter not submit input()

I wanted to be able to write paragraphs in the python console and then submit with something like SHIFT + ENTER but cant find a way to do it.

My code:

text = str(input("Enter the full text: "))
print(text)

Upvotes: 0

Views: 52

Answers (1)

CaptainObvious
CaptainObvious

Reputation: 109

I found your question quite interesting because the command line does not allow you to hit enter and continue with your paragraph but we can trick it into being able to input paragraphs by using a while loop to move to the next line and append the new line to the previous line and will only stop capturing the paragraph only when a command is entered.

def get_input():
    lines = []
    print("Enter your paragraph (type '/done' on a new line to finish):")
    while True:
        line = input()
        if line == "/done":
            break
        lines.append(line)
    return "\n".join(lines)

def main():
    input_text = get_input()
    print("Entered text:")
    print(input_text)

if __name__ == "__main__":
    main()

you only need to enter /done on a new line to breakout of the loop and save your paragraph

Upvotes: 0

Related Questions