Learning doesn’t stop, at any age!
Learning a little each day adds up!
In last session, we learned number manipulation in Python. Today we will learn input function in Python. Let’s get started!
Input function can be used to read data or input from the user in python. For example, you will be asked some information to input into certain webpages when shopping online, or you will be answering some questionnaires. What you have typed in is called input.
This can be done by using input() function. Let’s try below code.
age = input(“What is your age?”)
print(“My age is:” + age)
You should get below first:
What is your age?
Write down a number after above output, for example, 20. The print should show up as below.
My age is:20
Note, if you would like to enter your answer in the next line, then use “\n”. Check out below codes
age = input(“What is your age? \n”)
print(“My age is:” + age)
You will be entering the age a line below the “What is your age?” question.
What is your age?
20
My age is:20
You can also combine the user inputs, and use them together.
age = input(“What is your age? \n”)
name = input(“What is your name?\n”)
like = input(“What do you like? \n”)
print(“My name is: ” + name + “. I am ” +age+” year old. I like “+like +”!”)
You should get three questions that ask your inputs. After you input all of them, you should see a print. See below
What is your age?
20
What is your name?
XRKnows
What do you like?
apple
My name is: XRKnows. I am 20 year old. I like apple!
Is it cool? Yes. I love it.
You can practice input function with different ways. I hope this help you learn something about Python. If you have any questions or you see any issues with your code. Feel free to leave me message, i will try to help you resolve it.
Happy learning!