Python

Python program to calculate sum of natural numbers2 min read

In this tutorial, we will discuss Python program to add two number using function

In this topic, we will learn a simple concept of how to add two numbers using the function in the Python programming language




already we learned the same this concept using the operator in a simple way.

Program 1

Add two integer number using the function

When the above code is compiled and executed, it produces the following results

Add two integer number using the function – get input from the user

Program 2

When the above code is compiled and executed, it produces the following results

This is the program asked input from user two numbers and displays the sum of two numbers entered by the user

We can use pre-defined python function input() to takes input from the user. Input() function returns a string value. So we can use int() function to convert from string to int data type (shown in line 6 and 7).

Add two floating point number using the function

Program 3

Add two float numbers using the function – get input from the user

This is the program asked input from user two numbers and displays the sum of two numbers entered by the user

We can use pre-defined python function input() to takes input from the user. Input() function returns a string value. So we can use float() function to convert from string to float data type (shown in line 6 and 7).

Leave a Comment