Python, Accepting Input

In a Python command line application you can display information to the user using the print() function:

name = "Roger"
print(name)

We can also accept input from the user, using input():

print('What is your age?')
age = input()
print('Your age is ' + age)

This approach gets input at runtime, meaning the program will stop execution and will wait until the user types something and presses the enter key.

You can also do more complex input processing and accept input at program invocation time, and we’ll see how to do that later on.

This works for command line applications. Other kinds of applications will need a different way of accepting input.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

In a Python command line application you can display information to the user using the print() function:

name = "Roger"
print(name)

We can also accept input from the user, using input():

print('What is your age?')
age = input()
print('Your age is ' + age)

This approach gets input at runtime, meaning the program will stop execution and will wait until the user types something and presses the enter key.

You can also do more complex input processing and accept input at program invocation time, and we’ll see how to do that later on.

This works for command line applications. Other kinds of applications will need a different way of accepting input.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2020-12-06T05:00:00+00:00) Python, Accepting Input. Retrieved from https://www.scien.cx/2020/12/06/python-accepting-input/

MLA
" » Python, Accepting Input." flaviocopes.com | Sciencx - Sunday December 6, 2020, https://www.scien.cx/2020/12/06/python-accepting-input/
HARVARD
flaviocopes.com | Sciencx Sunday December 6, 2020 » Python, Accepting Input., viewed ,<https://www.scien.cx/2020/12/06/python-accepting-input/>
VANCOUVER
flaviocopes.com | Sciencx - » Python, Accepting Input. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/12/06/python-accepting-input/
CHICAGO
" » Python, Accepting Input." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2020/12/06/python-accepting-input/
IEEE
" » Python, Accepting Input." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2020/12/06/python-accepting-input/. [Accessed: ]
rf:citation
» Python, Accepting Input | flaviocopes.com | Sciencx | https://www.scien.cx/2020/12/06/python-accepting-input/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.