SwadhyAI Notes

All Python notes

Python How To Add Two Numbers ➕

Add Two Numbers

Learn how to add two numbers in Python.

✨ Add Two Numbers

Python has a built-in operator + for addition.

python
x = 5
y = 10
print(x + y)

✨ Add Two Numbers with User Input

In this example, the user must input two numbers. Then we print the sum by calculating (adding) the two numbers:

python
x = input("Type a number: ")
y = input("Type another number: ")

sum = int(x) + int(y)

print("The sum is: ", sum)

⚠️ Watch Out!

The input() function returns a string. You must convert it to an integer (or float) before you can perform mathematical operations on it.