0% found this document useful (0 votes)
6 views

PROGRAM

Uploaded by

Kartik Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PROGRAM

Uploaded by

Kartik Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PROGRAM-1

Q.WAP to calculate the frequency of the given list of numbers.

count=0

l=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l.append(ele)

item=int(input("enter the element to be searched:"))

for i in l:

if i==item:

count=count+1

print("The frequency of",item,"is",count)

OUTPUT:

enter the no. of elements:10

enter the element:12

enter the element:34

enter the element:12

enter the element:34

enter the element:56

enter the element:90

enter the element:12

enter the element:90

enter the element:23

enter the element:45

enter the no. to be searched:90

The Frequency of 90 is 2
PROGRAM-2

Q.Write a program to calculate mean of a given list of numbers.

sum=0

l=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l.append(ele)

for i in l:

sum=sum+i

mean=sum/n

print("the calculated mean is:",mean)

OUTPUT:

enter the no. of elements:6

enter the element:8

enter the element:4

enter the element:7

enter the element:9

enter the element:10

enter the element:11

the calculated mean is: 8.166666666666666


PROGRAM-3

Q.Write a program to accept a character from the user and display whether it is a vowel or
consonant.

ch=input("enter the character:")

if (ch=='a' or ch=='A'):

print(ch,"is a vowel")

elif (ch=='e' or ch=='E'):

print(ch,"is a vowel")

elif (ch=='i' or ch=='I'):

print(ch,"is a vowel")

elif (ch=='o' or ch=='O'):

print(ch,"is a vowel")

elif (ch=='u' or ch=='U'):

print(ch,"is a vowel")

else:

print(ch,"is a consonant")

OUTPUT:

=======================

enter the character:c

c is a consonant

enter the character:a

a is a vowel
PROGRAM-4

Q.WAP to accept percentage from the user and display the grade .

perc=int(input("Enter the marks:"))

if perc>90:

print("A")

elif perc>80 and perc<=90:

print("B")

elif perc>=60 and perc<=80:

print("C")

elif perc<60:

print("D")

else:

print("Fail")

OUTPUT:

Enter the marks:86

Enter the marks:67

C
PROGRAM-5

Q. WAP to print duplicates from a list of integers.

l=[1,2,1,2,3,4,5,1,1,2,5,6,7,8,9,9]

uniqueList=[]

duplicateList=[]

for i in l:

if i not in uniqueList:

uniqueList.append(i)

elif i not in duplicateList:

duplicateList.append(i)

print(duplicateList)

OUTPUT:

=======================

[1, 2, 5, 9]
PROGRAM-6

Q.Write a code to calculate and display total marks and percentage of a student from the given list
storing marks of a student.

total=0

l=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l.append(ele)

for i in l:

total=total+i

print("the total is:",total)

perc=(i/total)*100

print("the percentage is:",perc)

OUTPUT:

=======================

enter the no. of elements:5

enter the element:90

enter the element:89

enter the element:77

enter the element:45

enter the element:67

the total is: 368

the percentage is: 18.206521739130434


PROGRAM-7

Q.WAP to read a list of n integers and find their median.

l=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l.append(ele)

m=int(n/2)

print("The median is:",l[m])

OUTPUT:

=======================

enter the no. of elements:5

enter the element:12

enter the element:45

enter the element:90

enter the element:34

enter the element:21

The median is: 90


PROGRAM-8

Q.WAP that reads two numbers and an arithmetic operator and displays the result.

a=float(input("Enter the first number:"))

b=float(input("Enter the second number:"))

Op=input("Enter the operator:")

if Op=='+':

print(a+b)

elif Op=='-':

print(a-b)

elif Op=='*':

print(a*b)

elif Op=='/':

print(a/b)

elif Op=='%':

print(a%b)

elif Op=='**':

print(a**b)

else:

print("Invalid Option")

OUTPUT:

=======================

Enter the first number:6

Enter the second number:4

Enter the operator:**

1296.0
PROGRAM-9

Q.WAP to accept the number from the user and print the reverse of that number.

num=int(input("Enter a number:"))

rev_dig=0

while num!=0:

digit=num%10

rev_deg=rev_dig*10+digit

num//=10

print("Reverse of the number is",rev_dig)

OUTPUT:

Enter a number:80

Reverse of the number is 0


PROGRAM-10

Q. WAP to read alist of elements. Modify this list so that is does not contain any duplicate
elements,i.e.,all elements occuring multiple times in the list should only appear once.

l1=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l1.append(ele)

l2=[]

for j in l1:

if j not in l2:

l2.append(j)

print(l2)

OUTPUT:

=========================

enter the no. of elements:4

enter the element:2

enter the element:2

enter the element:3

enter the element:3

[2, 3]

=========================
PROGRAM-11
Q.Write a function to display prime numbers below 30.

for num in range(2,30):

is_prime=True

for i in range(2,num):

if num%i==0:

is_prime=False

break

if is_prime:

print(num)

OUTPUT:

11

13

17

19

23

29
PROGRAM-12

Q.WAP to multiply an element by 2 if it is odd index for a given list containing both numbers and
strings.

l=[]

n=int(input("enter the no. of elements:"))

for i in range(n):

ele=int(input("enter the element:"))

l.append(ele)

for i in range(len(l)):

if i%2!=0:

l[i]=l[i]*2

print("The updated list is:",l)

OUTPUT:

=======================

enter the no. of elements:8

enter the element:12

enter the element:21

enter the element:45

enter the element:33

enter the element:44

enter the element:21

enter the element:23

enter the element:90

The updated list is: [12, 42, 45, 66, 44, 42, 23, 180]

You might also like