Getting input from the user
inputto prompt the user to enter some data.
inputwill put a message on the screen, wait for the user to give a response and press Enter, and then store the response as text in a variable so you can use it in your program.
inputare examples of functions. Functions are pre-made programs which are typically created to perform a single task. Python has many inbuilt functions allowing you to perform a large range of tasks.
- Add the following code to the bottom of your program to use
inputto capture the user’s name and store it in a variable.
users_name = input("What is your name? ")
users_name =creates a variable called
users_nameand assigns it a value
input()uses the function
inputto display a prompt and capture the user’s response
"What is your name? "– the value between the
()– is the prompt which will be output to the screen
users_name) you can use the data in your program.
- Lets use
- Improve the output by adding some text to the start and end of the message.
print("Hello " + users_name + ", welcome.")
- Grab a friend, run your program and ask them to input their name.
Programming 101: An Introduction to Python for Educators
Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.