Python For GCSE
User Input

We are going to need most of our programs to take input from our user. We do this using the input statement.

Study the following code carefully,

name = input("Enter your name: ")
age = int(input("Enter your age: "))
height = float(input("Enter your height in metres: "))

print("Name:", name)
print("Age:", age)
print("Height:", height)

The first thing to note is that we need to use casting. The input statement returns a string. If we are looking to store numbers, we need to convert our input value into an integer or float.

The second thing to consider is the approach you are going to take to writing in your programs. By writing, I mean literacy. An input statement contains a prompt, a message asking a question or telling the user what to enter. I like to make use of capital letters and think about how my statements are going to look to the user when they enter text. I always use a colon and a space at the end of my prompts. If you don't put the space, the user will be typing directly next to your prompt. Some users will instinctively type a space if you do that - a space that you did not expect. It doesn't take a great deal of effort or concentration to make the program look nice from the user's perspective.

When you do casting, you are opening two sets of brackets. A common mistake that people make is not to close both pairs of brackets.