Python program to add two numbers Here are four easy methods to add to numbers in python programming language at kashifbaig250.blogspot.com just copy past in your python IDE.
They are already tested by us.
num1 = 2.5
num2 = 4.3
# First method to print
print( f' By M-1 The sum of {num1} and {num2} is
{num1+num2}')
# second method to print
print('By M-2 The sum of %.1f and %.1f is %.1f'%(num1,
num2, num1+num2))
#Third method to print
print('By M-3 The sum of {0} and {1} is {2}'.format(num1,
num2, num1+num2))
# OUTPUT:
# By M-1 The sum of 2.5 and 4.3 is 6.8
# By M-2 The sum of 2.5 and 4.3 is 6.8
# By M-3 The sum of 2.5 and 4.3 is 7.8
Fourth method to perform this addition in a single statement without using any variables as follows. This program uses no variable ( i.e memory efficient).
print(
'The sum is %.1f' %(float(
input(
'Enter first number: ')) + float(
input(
'Enter second number: '))))
🔗 1: Add Two Numbers
🔗 2: Swap two numbers
🔗 3: Even or odd
🔗 4: Python
Program to find Largest of Two Numbers
🔗 5: Largest of Three Numbers
🔗 6: Centigrade to Fahrenheit and
vice versa
🔗 7: Display calendar of the given
month and year
🔗 8: Area of Triangle
🔗 9: Sum of digits & number of digits
🔗 10: Check Leap year or not
🔗 11: Make Simple Calculator by Using Functions
🔗 12: Find Quarqratic equation roots