top of page

Python Program using function to calculate addition, substraction, multiplication and division



def add(a,b):

print("Addition of two numbers", a+b)

def sub(a,b):

print("Subtraction of Two numbers",a-b)

def mul(a,b):

print("Multiplication of two numbers", a*b)

def div(a,b):

print("Division of two numbers",a/b)

x=int(input("Enter first numbers: "))

y=int(input("Enter Second numbers: "))

add(x,y)

sub(x,y)

mul(x,y)

div(x,y)

Output:

Enter first numbers: 5

Enter Second numbers: 8

Addition of two numbers 13

Subtraction of Two numbers -3

Multiplication of two numbers 40

Division of two numbers 0.625


To check even or odd number using function

def even(a):

if a%2==0:

print("Number is even")

else:

print("Number is odd")

x=int(input("Enter a Number: "))

even(x)

Output:

Enter a Number: 12

Number is even

1,184 views0 comments

Recent Posts

See All

Python program to calculate the factorial of a number

Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument. This program is most for O Level Practical Exam so read it care

NumPy program to find the most frequent value in the list.

This program is most for O Level Practical Exam so read it carefully. Program: import numpy as np x = np.array([1,2,3,4,5,7,2,1,1,1,8,9,1]) print(x) print("most frequent value in the list:") print(np.

Komentar


bottom of page