Thursday, 15 February 2024

Class 11 CS Practical - 50

 

50 - Write a program in Python to count the frequency of all elements of a list.

L= [10, 20, 30, 20, 40, 30, 20, 50]

print("List is: ",L)

Uni= []

Freq= []

for i in L:

    if i in Uni:

        index=Uni.index(i)

        Freq[index]+= 1

    else:

        Uni.append(i)

        Freq.append(1)

for i in range(len(Uni)):

    print(Uni[i],":",Freq[i])


Output:

List is:  [10, 20, 30, 20, 40, 30, 20, 50]

10 : 1

20 : 3

30 : 2

40 : 1

50 : 1

Class 11 CS Practical - 49

 

49 - WAP in the Python to create a list and find the mean of all numeric values stored in the list.


L=eval(input("Enter a list: "))

n=len(L)

N=[]

for i in L:

    if isinstance(i,int) or isinstance(i,float):

        N.append(i)

print("Mean of numeric values stored in the list:")

print(sum(N)/len(N))


Output:

Enter a list: [5,'A',9,6.5,'Python',3.5]

Mean of numeric values stored in the list:

6.0



Class 11 CS Practical - 48

 

48 - WAP in Python to create a dictionary with name of employee, their salary and access them.


Emp={}

c='y'

while c in 'yY':

    name=input("Enter the name of employee: ")

    salary=float(input("Enter the salary of employee: "))

    Emp[name]=salary

    c=input("Do you want to add more emp(y/n): ")

print("Details of Employee:")

print(Emp)

Output:

Enter the name of employee: Ram

Enter the salary of employee: 38545

Do you want to add more emp(y/n): y

Enter the name of employee: Raj

Enter the salary of employee: 45854

Do you want to add more emp(y/n): y

Enter the name of employee: Aman

Enter the salary of employee: 47825

Do you want to add more emp(y/n): n

Details of Employee:

{'Ram': 38545.0, 'Raj': 45854.0, 'Aman': 47825.0}


Class 11 CS Practical - 47

 47 - WAP in Python to input a string and display the frequency of each character using dictionary


S=input("Enter a string: ")

F={}

for i in S:

    if i in F:

        F[i]+=1

    else:

        F[i]=1

print("Frequency of characters in the given string: ")

for i, j in F.items():

    print(i,":",j)



Output:

Enter a string: S P SHARMA

Frequency of characters in the given string:

S : 2

  : 2

P : 1

H : 1

A : 2

R : 1

M : 1


Wednesday, 14 February 2024

Class 11 CS Practical - 46

 

46 - Write a program in Python to input the value of x and n and print the sum of the following series:

x + x2/2! + x3/3! + x4/4! + -------- xn /n!

import math as m

x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(1,n+1):

    sum=sum+pow(x,i)/m.factorial(i)

  print("Sum of the series=",sum)



Output:

Enter the value of x: 2

Enter the value of n: 3

Sum of the series= 5.333333333333333

 

Enter the value of x: 2

Enter the value of n: 4

Sum of the series= 6.0






Class 11 CS Practical - 45

 

45 - Write a program in Python to input the value of x and n and print the sum of the following series:

x + x2/2 + x3/3 + x4/4 + -------- xn /n


x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(1,n+1):

    sum=sum+pow(x,i)/i

print("Sum of the series=",sum)



Output:

Enter the value of x: 2

Enter the value of n: 3

Sum of the series= 6.666666666666666

 

Enter the value of x: 2

Enter the value of n: 4

Sum of the series= 10.666666666666666


Class 11 CS Practical - 44

 

44 - Write a program in Python to input the value of x and n and print the sum of the following series:

1 - x + x2 - x3 +x4 + -------- xn


x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(0,n+1):

    if i%2==0:

        sum=sum+pow(x,i)

    else:

        sum=sum-pow(x,i)

print("Sum of the series=",sum)


Output:


Enter the value of x: 2

Enter the value of n: 3

Sum of the series= -5

 

Enter the value of x: 2

Enter the value of n: 4

Sum of the series= 11






Class 11 CS Practical - 43

 43 - Write a program in Python to input the value of x and n and print the sum of the following series:

1 + x + x2 + x3 +x4 + -------- xn

x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(0,n+1):

    sum=sum+pow(x,i)

print("Sum of the series=",sum)


Output:

Enter the value of x: 2

Enter the value of n: 3

Sum of the series= 15

 

Enter the value of x: 2

Enter the value of n: 4

Sum of the series= 31


Class 11 CS Practical - 42

 

42 - Write a program in Python to create a list of 10 random numbers between 1 to 100.


import random as r

L=[]

for i in range(0,10):

    a=r.randrange(1,100)

    L.append(a)

print("List of 10 random numbers between 1 to 100:")

print(L)



Output:

List of 10 random numbers between 1 to 100:

[60, 67, 55, 66, 85, 82, 73, 67, 62, 57]


Class 11 CS Practical - 41

 

41 -  Write a program in Python to input a list of numbers and find the mean, mode and median.


import statistics as s

L=[]

n=int(input("Enter the size of the list: "))

for i in range(0,n):

    a=int(input("Enter element of List: "))

    L.append(a)

print("List is: ", L)

print("Mean of the given data: ",s.mean(L))

print("Mode of the given data: ",s.mode(L))

print("Median of the given data: ",s.median(L))


Output:

Enter the size of the list: 5

Enter element of List: 8

Enter element of List: 9

Enter element of List: 3

Enter element of List: 9

Enter element of List: 7

List is:  [8, 9, 3, 9, 7]

Mean of the given data:  7.2

Mode of the given data:  9

Median of the given data:  8

 


Enter the size of the list: 6

Enter element of List: 2

Enter element of List: 8

Enter element of List: 9

Enter element of List: 4

Enter element of List: 7

Enter element of List: 9

List is:  [2, 8, 9, 4, 7, 9]

Mean of the given data:  6.5

Mode of the given data:  9

Median of the given data:  7.5