Variables allow us to store information or data that our program needs. There are four variable types:
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
In Python, we can get input from the user using the input function.
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.
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"))
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.)