Wednesday 14 February 2024

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

Class 11 CS Practical - 36

 

36 - Write a program in Python to Input a tuple of numbers and find the smallest number in a list.


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

print("Tuple is: \n", T)

print("Minimum(Smallest) number of the Tuple = ",min(T))


Output:

Tuple is: 

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

Minimum(Smallest) number of the Tuple =  2


Class 11 CS Practical - 35

 

35 - Write a program in Python to Input a tuple of numbers and find the largest number in a tuple.


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

print("Tuple is: \n", T)

print("Maximum(Largest) number of the Tuple = ",max(T))


Output:

Tuple is: 

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

Maximum(Largest) number of the Tuple =  9

Class 11 CS Practical - 34

 

34 - Write a program in Python to Input a list of numbers and find the smallest number in a list.


L=[]

c='y'

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

    a=int(input("Enter an integer number to append in the list: "))

    L.append(a)

    c=input("Do you want to add more elements in the list (Y/N): ")

print("List is: \n", L)

print("Minimum(Smallest) number of the list = ",min(L))


Output:


Enter an integer number to append in the list: 5

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 8

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 2

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 9

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 4

Do you want to add more elements in the list (Y/N): n

List is: 

 [5, 8, 2, 9, 4]

Minimum(Smallest) number of the list =  2

Class 11 CS Practical - 33

 

33 - Write a program in Python to Input a list of numbers and find the largest number in a list. 


L=[]

c='y'

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

    a=int(input("Enter an integer number to append in the list: "))

    L.append(a)

    c=input("Do you want to add more elements in the list (Y/N): ")

print("List is: \n", L)

print("Maximum(Largest) number of the list = ",max(L))


Output:

Enter an integer number to append in the list: 5

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 8

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 2

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 9

Do you want to add more elements in the list (Y/N): y

Enter an integer number to append in the list: 4

Do you want to add more elements in the list (Y/N): n

List is: 

 [5, 8, 2, 9, 4]

Maximum(Largest) number of the list =  9

Class 11 CS Practical - 32

 

32 - Write a program in Python to input a string and convert the case of characters (uppercase to lowercase and lowercase to uppercase) in the string. 


S=input("Enter a string: ")

NS=''

for i in range(0,len(S)):

    if S[i].isupper():

        NS+=S[i].lower()

    elif S[i].islower():

        NS+=S[i].upper()

    else:

        NS+=S[i]

print("New String = ",NS)


Output:

Enter a string: Python @ PrograMMing

New String =  pYTHON @ pROGRAmmING



Class 11 CS Practical - 31

 

31 - Write a program in Python to input a string, then Count and display the number of vowels, consonants, uppercase, lowercase characters in string.


S=input("Enter a string: ")

v=0

c=0

u=0

l=0

print("Total number of characters in the string = ", len(S))

for i in S:

    if i in 'aeiouAEIOU':

        v=v+1

    elif i>='a' and i<='z':

        c=c+1

    elif i>='A' and i<='Z':

        c=c+1

print("Number of Vowels = ", v)

print("Number of consonants = ", c)

for i in S:

    if i.isupper():

        u=u+1

    elif i.islower():

        l=l+1

print("Number of uppercase letters = ", u)

print("Number of lowercase letters = ", l)


Output:

Enter a string: This is a Python Program

Total number of characters in the string =  24

Number of Vowels =  6

Number of consonants =  14

Number of uppercase letters =  3

Number of lowercase letters =  17



Enter a string: S@chin P@r@sh@r

Total number of characters in the string =  15

Number of Vowels =  1

Number of consonants =  9

Number of uppercase letters =  2

Number of lowercase letters =  8