Variable Types

Variables allow us to store information or data that our program needs. There are four variable types:

  • String - this is any data that includes letters
  • Integer - this is a whole number
  • Real - this is a number with a decimal point
  • Boolean - this is something that is said to be either true or false

Examples of each of these include:

String: “x”, “Hello”, “Welcome to Computing”

Integer: 45, 89, 19, 20

Real: 12.2, 78.2

Boolean: Boolean values can only be True or False

Python Input

In Python, we can get input from the user using the input function.

String input

When we want to get a string from the user we can do something like:

persons_name = input("Please enter your name")

Note: the “Please enter your name” is just the message that will appear. It is what the user enters that is important. In this case they might enter Samantha - which of course is a string.

Integer Input

When we want to enter an integer then we have to put the int function in front of the input function.

Here’s how we might get a user to enter their age:

persons_age = int(input("Please enter your age"))

Real Input

Similar to integers, when we want the user to enter a real number we do:

persons_height = float(input("Please enter your height"))

(Notice that although we call the variable type real, in Python it is called float.)