WAP to Add Two Numbers in Python. In this tutorial, we will learn how to write a simple Python program that adds two numbers together. This is a basic programming exercise that can help beginners understand how to use Python for arithmetic operations.
Table of Contents
Python Program to Add Two Numbers
# get input from the user
num1 = float(input("Enter the first number "))
num2 = float(input("Enter the second number "))
# Calculate the sum
sum = num1 + num2
print("The sum of num1 and num2 is ", sum)
In the above code-
- The first line asks a user to enter a number and converts the input from string to float.
- Similar to the first line the second line asks the user to enter the second number.
- The third line calculates the sum of two numbers in Python.
- The last line prints the result.
Happy Coding & Learning
1 thought on “WAP to Add Two Numbers in Python”