Previous

Variables and Types

3 / 6
Next

Python programs can also take numbers as input and do calculations.

print("Input a number: ")
n = input()
print(n, "multiplied by 3 is", 3*n)

The program above is wrong. The input n is seen not as a number but as a string of characters. This means that if we input 15 to the program then n will contain the characters '1' and '5', not the number 15. To interpret it as a number, we have to cast it to an int:

print("Input a number: ")
n = int(input())
print(n, "multiplied by 3 is", 3*n)

Int stands for integer, which is a whole number; no fractions or decimal digits.

Send

Textual and numeric data

Hint
Beginner

Input two numbers, add them together, and print the result.

Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!