0% found this document useful (0 votes)
19 views2 pages

Python Functions for Basic Math Operations

The document contains a Python script that defines several functions for basic arithmetic operations including addition, subtraction, multiplication, and division. It allows users to input numbers and perform calculations interactively through a menu-driven loop. The script also includes specific functions for adding three numbers and demonstrates the use of function parameters and return values.

Uploaded by

shitijablah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Python Functions for Basic Math Operations

The document contains a Python script that defines several functions for basic arithmetic operations including addition, subtraction, multiplication, and division. It allows users to input numbers and perform calculations interactively through a menu-driven loop. The script also includes specific functions for adding three numbers and demonstrates the use of function parameters and return values.

Uploaded by

shitijablah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment 6

#addition of 3 numbers using func


def fun4(a,b):
return a+b
def fun5():
i = int(input("Enter num1: "))
j = int(input("Enter num2: "))
k = int(input("Enter num3: "))
return i + fun4(j,k)
print("Sum of three numbers: ", fun5())
#addition and subtraction of two numbers using func
def fun1():
i = 24
j = 56
return i+j
print()
print("Addition is ", fun1())
def fun2(a,b):
return a+b
def fun3(a,b):
return a+b, a-b
n1 = int(input("Enter number 1: "))
n2 = int(input("Enter number 2: "))
print("Addition is ", fun2(n1,n2))
c,d = fun3(n1,n2)
print("Sum is ", c ,"and Subtraction is ", d)
def inp():
a = int(input("Enter number 1: "))
b = int(input("Enter number 2: "))
return a,b
def add():
x,y = inp()
return x+y
def sub():
x,y = inp()
return x-y
def div():
x,y = inp()
return x/y
def mul():
x,y = inp()
return x*y
while(True):
print("\n1: Add\n2: Subtract\n3: Multiply\n4: Divide\n5: Quit")
ch = int(input("Enter Choice: "))
if(ch == 1):
print("Addition is: ",add())
elif(ch == 2):
print("Subtraction is: ",sub())
elif(ch == 3):
print("Subtraction is: ",mul())
elif(ch == 4):
print("Subtraction is: ",div())
elif(ch == 5):
break

You might also like