Professional Documents
Culture Documents
calculator to perform
CODE:-
(a)
print("Add : 1")
print("Subtract : 2")
print("Multiply : 3")
print("Divide : 4")
x = int(input("Your choice : "))
if x == 1:
def plus(num1,num2):
print(num1+num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
plus(num1,num2)
elif x == 2:
def minus(num1,num2):
print(num1-num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
minus(num1,num2)
elif x == 3:
def multiply(num1,num2):
print(num1*num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
multiply(num1,num2)
elif x == 4:
def divide(num1,num2):
print(num1/num2)
return
num1 = int(input("Enter 1st number :"))
num2 = int(input("Enter 2nd number :"))
divide(num1,num2)
OUTPUT:-
Add : 1
Subtract : 2
Multiply : 3
Divide : 4
Your choice : 2
Enter 1st number :23
Enter 2nd number :32
(b)
Code:-
import math
print("log10(x) : 1")
print("sin(x) : 2")
print("cos (x) : 3")
x = int(input("Enter your choice : "))
if x == 1:
def myfunc1(num):
print(math.log10(num))
return
num = int(input("Enter number : "))
myfunc1(num)
elif x == 2:
def myfunc2(num):
print(math.sin(num))
return
num = int(input("Enter number : "))
myfunc2(num)
elif x == 3:
def myfunc3(num):
print(math.cos(num))
return
num = int(input("Enter number : "))
myfunc3(num)
output:-
log10(x) : 1
sin(x) : 2
cos (x) : 3
Enter your choice : 2
Enter number : 24
-0.9055783620066239
---PROGRAM 2---
#program to print Fibonacci series up to certain limit (using
“while”)
Platform:-google colab
CODE:-
n=int(input("ENTER NUMBER UPTO YOU WANT THE SERIES:"))
num1=0
num2=1
next_number = num2
count = 1
OUTPUT:-
ENTER NUMBER UPTO YOU WANT THE SERIES:10
123581321345589
--------PROGRAM 3--------
#program to print pascal triangle
Plateform:- google colab
CODE:-
def generate_pascal_triangle(n):
pascal_triangle = []
for line in range(1, n + 1):
row = []
for i in range(line):
if i == 0 or i == line - 1:
row.append(1)
else:
prev_row = pascal_triangle[-1]
row.append(prev_row[i - 1] + prev_row[i])
pascal_triangle.append(row)
OUTPUT:-
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
--------PROGRAM 14--------
# Write a python program which contains user defined functions as a 'module' to calculate area,
perimeter or surface area , volume for various shapes like square, cube, circle, cylinder. The user
defined functions should accept the values for calculation as parameters and calculated values
should be returned. Import the module and use appropriate functions.
Platform:-GOOGLE COLAB
CODE:-
print("Square: 1")
print("Cube : 2")
print("Circle : 3")
print("Cylinder : 4")
x = int(input("Enter your choice : "))
if x == 1:
def square(a):
print("Area of square is :",a*a)
print("Perimeter of square is :",4*a)
return
a = int(input("Enter side of square : "))
square(a)
elif x == 2:
def cube(a):
print("Surface area of cube is :",6*a*a)
print("Volume of cube is :",a*a*a)
return
a = int(input("Enter side of cube : "))
cube(a)
elif x == 3:
def circle(r):
print("Perimeter of circle is :",2*3.14*r)
print("Area of circle is :",3.14*r*r)
return
r = int(input("Enter radius of circle : "))
circle(r)
elif x == 4:
def cylinder(r,h):
print("Surface area of cylinder is :",2*3.14*r*r + 2*3.14*r*h)
print("Volume of cylinder is :",3.14*r*r*h)
return
r = int(input("Enter radius of cyliner : "))
h = int(input("Enter height of cyliner : "))
cylinder(r,h)
OUTPUT:-
Square: 1
Cube : 2
Circle : 3
Cylinder : 4
Enter your choice : 4
Enter radius of cyliner : 67
Enter height of cyliner : 43
Surface area of cylinder is :
46283.6
Volume of cylinder is :
606104.7799999999