Python uses the input() function to obtain input from the user. The input function will wait for some input from the keyword. To begin with you will ask the user for their name and store this in a variable called name. Enter the following into a text file called input.py.
# This program will ask for the age of the user and output a message.
#get the age of the user
age = input(‘What is your age? ‘)
#display a hello messagae
print(‘I did not know that you are ‘)
First the program is commented by using the # symbol. This is ignored by Python and is only a reference for the programmer or someone reading your source code. Next the program uses the input function which passes in a message to be displayed on screen. The input function is used to obtain the age which is stored in the age variable.
Finally the print function is used to display a message and then the age.
Download the PDF file for Week 8 – Day 4 – Python input function