Simple Arithmetic, Input and Output in Python

Simple Maths with input()

x = 2 * y

What is the value of ‘x’ when ‘y = 3’ ?

x = 2 * 3 
x = 6
y = 3
x = 2 * y
print(x)

“x” and “y” are called the variables of this program.

Let's modify the code to receive input from the user:

y = input("Enter a number please: ")     
x = 2 * y
print (x)

The terminal prompt will be expecting a user input, type any number you wish. e.g. 23

Output is 2323, why is that?

The input function reads the input as a string literal, and it stores the value as a text inside the y variable. Python has a special feature of duplicating strings with the * operator, and the result is also a string value stred in the xvariable.

There are special functions for reading numbers.