In this tutorial, we will discuss the Python program to the sum of two numbers
In this topic, we will learn how to add two numbers in Python programming language
#find sum of two integer numbers f_no=35 #variable declaration s_no=55 sum=f_no + s_no;#Adding the two numbers print("The sum of numbers", sum) #display the results on the screen
When the above code is compiled and executed, it produces the following results
The sum of numbers 90
#assingning the two float values val_1=34.56; val_2=45.67; #find sum of two values sum=float(val_1)+float(val_2) #Display the result of sum print("The sum of numbers is: ",sum)
When the above code is compiled and executed, it produces the following results
The sum of numbers is: 80.23
#get input from user for num_1, num_2 num_1=float(input("Enter the first number: ")) num_2=float(input("Enter the second number: ")) #find sum of given numbers sum=num_1 + num_2 #Display the result on the screen print("The sum of two numbers: ",sum)
When the above code is compiled and executed, it produces the following results
Enter the first number: 12.34 Enter the second number: 23.45 The sum of two numbers: 35.79
In the above program, the user is entered two floating point value for find sum.
we use the pre-defined function input() for getting value from the user. but, these function returns a output as the string. So, we can convert it using the float() function to display floating point values
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…