Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Does an input call prevent all following code from running until its received input?
Hey all, new to python and I'm currently taking the python basics course. In the "if, else, and elifs" video it has us request the users first name with the input() function. I noticed that if i insert random code after the input call, such as print("Hey man"), it won't run/print until the input has been received even though the two are irrelevant to each other . Is this normal? Am i right in assuming that any code after an input() call in a script won't run until the input has been received?
Thanks in advance
Jason AndersTreehouse Moderator 145,841 Points
Hi Brent. Welcome to Python.
You're right in thinking that the code essentially stops until input is received when executing the
input() function call. This isn't unique to Python, but any language really. When you are asking for user input, the code stops until some input is received. The reason, generally, would be that if your asking for input, the code after is probably going to be doing something with that input, so the code is waiting for the input before proceeding.
When you say even your "random code" doesn't run, this is because code really is not smart. It doesn't know what the code is going to do until it does it. It doesn't know if the input is needed or not, so it just waits.
Hope that help to make sense.