Home 07. Add two numbers | Exercise
Post
Cancel

07. Add two numbers | Exercise

Write a program to add two numbers using input() function.

Solution 1

1
2
3
4
5
6
7
8
9
# Add two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Sum of", num1, "and", num2, "is", num1 + num2)

# Output
# Enter first number: 12
# Enter second number: 13
# Sum of these two numbers is: 25

Solution 2

1
2
3
# Add two numbers
a, b = input("Enter two number: ").split()
print("Sum of two number:", int(a) + int(b))
This post is licensed under CC BY 4.0 by the author.

06. Input Function in Python

08. String Slicing and their Fuctions