Variables in Python

In Python, information is stored in variables. We have already interacted with variables before when getting inputs from the user.
name = input()
surname = input()
print(name, '--', surname)
This program reads two inputs and stores them in variables. The first input is stored in a variable called name, and the second input is stored in a variable called surname.
For example, if the user inputs Nikola for the first input and Tesla for the second input, the name variable will store the value Nikola and the surname variable will store the value Tesla. Whenever these variables are printed, they will display their respective values.
Variables can be used to store any type of information. They can store textual information as shown in the example above, they can store numbers, they can store collections, and other structures.
To store numeric values in variables we can do the following:
a = 10
b = 400
print(a, b, a * b)
The program will print 10 400 4000.
This program stores 10 in a variable called a, 400 in a variable called b, and then prints their values along with the multiple of those two.


Write a program that stores -20 in a variable called x, 30 in a variable called y, and 100 in a variable called z. Print the result of the x * y + z expression.
So, we can use Python to do basic arithmetic operations and use it as a simple calculator.


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue