All Python Programs

All Programs

Basic Python Programs

Simple Python programs

If Condition Programs

If condition based Python Programs 

Looping based programs

program based on for loop, while loop, range

Searching and Sorting

Python Searching Programs
Python Sorting Programs

Python program to print sum of two numbers

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments
Solution using functions and by passing arguments and returning values


Solution : Without using function
Program/Source Code

Sum of two numbers

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=a+b
print("Sum = ",c)

Output:

Enter 1st no 10
Enter 2nd no 20
Sum = 30
>>>



Solution : Using function Without Passing Arguments
Program/Source Code

#function definition

def sum():
    a=int(input("Enter 1st no "))
    b=int(input("Enter 2nd no "))
    c=a+b
    print("Sum = ",c)

#function calling
sum()

Output:

Enter 1st no 25
Enter 2nd no 63
Sum = 88
>>>



Solution : Using function Passing Arguments
Program/Source Code

#function definition

def sum(n1,n2):
    s=n1+n2
    print("Sum = ",s)

#function calling
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
sum(a,b)

Output:

Enter 1st no 14
Enter 2nd no 523
Sum = 537
>>>



Solution using functions and by passing arguments and returning values
Program/Source Code

#function definition
def sum(n1,n2):
    s=n1+n2
    return s

#function calling
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=sum(a,b)
print("Sum = ",c)

Output:

Enter 1st no 100
Enter 2nd no 500
Sum = 600
>>>

Next : Python program to print square and cube of a number

You May Also Like:

Python program to calculate and print area and perimeter of square
Python Program to Find Factorial of Number Using Loop
C Language Program to Print Fibonacci Series
Python Program for Prime Number
Python Program to check character is an alphabet or not
C Language Program for Prime Number

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial
Advanced Python Tutorial
C Language
C++ Programming
Python programming

C Interview Questions
C++ Interview Questions
Python Interview Questions
HTML Interview Questions


Visitor Counter

0142288