Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Experiment 1: Read a list of numbers and write a program to check whether a

particular element is present or not using membership operators.

Aim: To read a list of numbers and write a program to check whether a


particular element is present or not using membership operators.

Description :
Python that searches an element in a list. Here both element and list must be
entered by user at run-time.
 Search an element in a list of n elements
 Check if a value exists in a given list, using in operator
Step 1: Enter the size of the list
Step 2: After entering the size of the list it will goes to
Step 3: Enter n elements for the list
Step 4: now enter ‘n’ elements
Step 5: Now u can enter the search element
Step 6: search element found at position

Program:

mylist = list()

print("Enter the size of list: ", end="")


tot = int(input())

print("Enter", tot, "elements for the list: ", end="")


for i in range(tot):
mylist.append(input())

print("\n Enter an element to be search: ", end="")


elem = input()

for i in range(tot):
if elem == mylist[i]:
print("\n Element found at Position:", i+1)
else:
print("\n Element not in the list.")
EXPECTED OUTPUT:

Enter the size of list: 6


Enter 6 elements for the list: 50
51
52
53
54
55

Enter an element to be search: 52

Element found at Position: 2

Enter an element to be search: 69

Element not in the list.

OUTPUT:

Enter the size of list: 6


Enter 6 elements for the list: 50
51
52
53
54
55

Enter an element to be search: 52

Element found at Position: 2


Enter an element to be search: 69

Element not in the list.


Experiment 3: Read radius and height of a cone and write a program to find the
volume of a cone

Aim : To read radius and height of a cone and write a program to find the
volume of a cone

Description :

If we know the radius and Slant of a Cone then we calculate the Surface Area of
Cone using the below formula:
Surface Area = Area of the Cone + Area of Circle
Surface Area = πrl + πr²
Where r = radius and
l = Slant (Length of an edge from top of the cone to edge of a cone)

The amount of space inside the Cone is called as Volume. If we know the radius
and height of the Cone then we can calculate the Volume using the formula:
Volume = 1/3 πr²h (where h= height of a Cone)

Program:

# Python Program to find Volume and Surface Area of a Cone

import math

radius = float(input('Please Enter the Radius of a Cone: '))


height = float(input('Please Enter the Height of a Cone: '))

# Calculate Length of a Slide (Slant)


l = math.sqrt(radius * radius + height * height)

# Calculate the Surface Area


SA = math.pi * radius * (radius + l)

# Calculate the Volume


Volume = (1.0/3) * math.pi * radius * radius * height
# Calculate the Lateral Surface Area
LSA = math.pi * radius * l

print("\n Length of a Side (Slant)of a Cone = %.2f" %l)


print(" The Surface Area of a Cone = %.2f " %SA)
print(" The Volume of a Cone = %.2f" %Volume);
print(" The Lateral Surface Area of a Cone = %.2f " %LSA)

Expected output :

Please Enter the Radius of a Cone: 5

Please Enter the Height of a Cone: 12

Length of a Side (Slant)of a Cone = 13


The Surface Area of a Cone = 282.74
The Volume of a Cone = 314.16
The Lateral Surface Area of a Cone = 204.20

Output :

Please Enter the Radius of a Cone: 5

Please Enter the Height of a Cone: 12

Length of a Side (Slant)of a Cone = 13


The Surface Area of a Cone = 282.74
The Volume of a Cone = 314.16
The Lateral Surface Area of a Cone = 204.20

You might also like