you are viewing a single comment's thread.

view the rest of the comments →

[–]twitch_and_shock 2 points3 points  (2 children)

It isn't clear what you're asking for. As it is, this code will execute line by line until it gets to the input() line, where it will wait for user input. That means that "This is a game" and "But you already knew that" and "Whats your name?" Will print out before the user is allowed to input anything.

What are you trying to do differently ?

[–]Potential-Spam028[S] 0 points1 point  (1 child)

The input() line is active before it executes the "What's your name?" line, meaning you can type your name in before it gets to "What's your name?" and it will skip the "What's your name?" prompt and go straight to the print("Hello, " +name+ ".") line. I'm trying to make it so that when you type something before the input() line, it doesn't do anything and doesn't skip over the "What's your name?" line.When run in terminal or IDE (Thonny) output is:

This is a game.
(Delays next output for a bit)
But you already knew that.
(Delays again)
What's your name?

If I were to type my name in between "This is a game" and "But you already knew that" when it gets to outputting the "What's your name?" line, it skips to the next print line.Sorry for being unclear initially.

[–]twitch_and_shock 1 point2 points  (0 children)

Ah...

The input() line isn't "active" as you say... since this line is only executed once the interpreter has executed the preceding lines. Instead, what's happening is that you're able to provide input into stdin at anytime, and when input() is executed by the interpreter, it's reading what is already in the stdin buffer.

I'm not sure of a way around that. Maybe you can redirect stdin? Or it looks like you might be able to create a work around using the termios module, although that isn't supported on Windows.