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


Class 11 CS Practical - 40


40 - Write a program in Python to create a dictionary with the roll number, name and marks of n students of a class and display the name of students who have marks above 75.



n=int(input("Enter the number of students: "))

D={}

RN=[]

Name=[]

Marks=[]

for i in range(0,n):

    roll_no = int(input("Enter the roll number of the student: "))

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

    marks=int(input("Enter the marks of the student: "))

    RN.append(roll_no)

    Name.append(name)

    Marks.append(marks)

D["Roll Number"]=RN

D["Name"]=Name

D["Marks"]=Marks

print("Dictionary of all students is: ",D)

print("Name of students who have marks above 75: ")

for i in range(0,n):

    if D["Marks"][i]>=75:

        print(D["Name"][i])




Output:

Enter the number of students: 5

Enter the roll number of the student: 1

Enter the name of the student: Ram

Enter the marks of the student: 78

Enter the roll number of the student: 2

Enter the name of the student: Raj

Enter the marks of the student: 48

Enter the roll number of the student: 3

Enter the name of the student: Sam

Enter the marks of the student: 79

Enter the roll number of the student: 4

Enter the name of the student: John

Enter the marks of the student: 84

Enter the roll number of the student: 5

Enter the name of the student: Amit

Enter the marks of the student: 67

Dictionary of all students is:  {'Roll Number': [1, 2, 3, 4, 5], 'Name': ['Ram', 'Raj', 'Sam', 'John', 'Amit'], 'Marks': [78, 48, 79, 84, 67]}

Name of students who have marks above 75:

Ram

Sam

John


Class 11 CS Practical - 37

 37 - Write a program in Python to Input a list of numbers and swap elements at the even location with the elements at the odd location. 

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)

if n%2!=0:

    n=n-1

for i in range(0,n,2):

    L[i],L[i+1]=L[i+1],L[i]

print("Updated list is: ", L)




Output:

Enter the size of the list: 5

Enter element of List: 2

Enter element of List: 8

Enter element of List: 6

Enter element of List: 4

Enter element of List: 7

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

Updated list is: [8, 2, 4, 6, 7]


Enter the size of the list: 6

Enter element of List: 2

Enter element of List: 8

Enter element of List: 6

Enter element of List: 4

Enter element of List: 7

Enter element of List: 9

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

Updated list is: [8, 2, 4, 6, 9, 7]






Class 11 CS Practical - 38

38 - Write a program in Python to Input a list of numbers and find the index of a specific element. 


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

print("List is : ",L)

c='Y'

while c=='Y' or c=='y':

    n=int(input("Enter the number to be search in the List: "))

    found=False

    for i in L:

        if i==n:

            print("Element found at index: ",L.index(i))

            found=True

    if found==False:

        print("Number is not found in the list")

    c=input("Do you want to search more item (Y/N): ")


Output:

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

Enter the number to be search in the List: 30

Element found at index:  2

Do you want to search more item (Y/N): y

Enter the number to be search in the List: 50

Element found at index:  4

Do you want to search more item (Y/N): y

Enter the number to be search in the List: 15

Number is not found in the list

Do you want to search more item (Y/N): n



Class 11 CS Practical - 39

39 - Write a program in Python to Input a tuple of numbers and find the index of a specific element. 


T= (5, 8, 9, 2, 6)

print("Tuple is : ",T)

c='Y'

while c=='Y' or c=='y':

    n=int(input("Enter the number to be search in the tuple: "))

    found=False

    for i in T:

        if i==n:

            print("Element found at index: ",T.index(i))

            found=True

    if found==False:

        print("Number is not found in the tuple")

    c=input("Do you want to search more item (Y/N): ")


Output:

Tuple is :  (5, 8, 9, 2, 6)

Enter the number to be search in the tuple: 8

Element found at index:  1

Do you want to search more item (Y/N): y

Enter the number to be search in the tuple: 2

Element found at index:  3

Do you want to search more item (Y/N): y

Enter the number to be search in the tuple: 7

Number is not found in the tuple

Do you want to search more item (Y/N): n