CS Practical File Class 11 Cbse

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

MAXFORT SCHOOL ROHINI

PRACTICAL FILE

SUBJECT: Computer Science

Class: XI

Submitted By: Submitted To:

Name: Prithvi Singh Chohan Mrs Pinky Gupta

Class/Sec : XI-A

Roll No. 35 HOD (C.S)


Programs on Python Strings

#question 1

inp_1 = input("Enter the string: ")

#taking inputs from the user

inp_2 = input("Enter the character to count: ")

j= 0

#taking a counter and counting the character

for i in inp_1:

if i == inp_2:

j += 1

#displaying the result

print(inp_2, " occurs ",j, " times")


#question 2

inp_1 = input("Enter the string: ")

#taking input and reversing

print(inp_1[::-1])S
#question 3

inp_1 = input("Enter the string: ")

#taking input and reversing and checking for similarity

x = inp_1[::-1]

if x == inp_1:

print("Yes, it's a Palindrome!")

else:

print("Oops!, it's not a palindrome")


#question 4

inp_1 = input("Enter the string: ")

#splitting the string and taking their length

x = inp_1.split()

y = len(x)

print("There are ",y, " words in ",inp_1)


#question 5

inp_1 = input("Enter the string: ")

x = inp_1.split()

#taking input and splitting it

y=0

#taking a counter and checking for each word as per the conditon

for i in x:

if i[0] == 'a':

a += 1

elif i[0] == 'A':

a += 1

else:

continue

print(y)
#question 6

inp_1 = input("Enter the string: ")

x = inp_1.split()

#splitting the words and then capitalizing

for i in x:

print(i.capitalize(), end=" ")


#question 7

inp_1 = input("Enter the sentence: ")

x = inp_1.split()

#splitting the words and checking for 'the' to replace with 'that'

for i in x:

if i.lower() == "the":

i = "that"

print(i, end=" ")

else:

print(i, end=" ")

continue
#question 8

cl =
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

sl = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

num = ['0','1','2','3','4','5','6','7','8','9']

#making lists for different sets for each case and counters

a, b, c = 0, 0, 0

inp_1 = input("Enter the string here: ")

#taking the length for the range() in for loop

for i in range(len(inp_1)):

if inp_1[i] in cl:

a += 1

elif inp_1[i] in sl:

b += 1

elif inp_1[i] in num:

c += 1

print("Capital Letters",a)
print("Small Letters",b) #displaying the results

print("Numbers",c)
#question 9

cl =
['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

sl = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

#making lists for the different cases

#making counters

a=0

b=0

inp_1 = input("Enter the string here: ")

#taking the length for the range() in for loop

_len = len(inp_1)

for i in range(_len):

if inp_1[i] in cl:

a += 1

elif inp_1[i] in sl:

b += 1

print("Uppercase",a) #displaying the results

print("Lowercase",b)
#question 10

cl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

sl = 'abcdefghijklmnopqrstuvwxyz'

#making variables for different cases

inp_1 = input("Enter your string: ")

#using for loop to access each character and change them

#capital to * and small to @

for i in inp_1:

if i in cl:

i = '*'

print(i,end='')

elif i in sl:

i = '@'

print(i,end='')

else:

print(i,end='')

continue
Programs on Python Lists

#question 1

list1 = []

inp_1 = int(input("Enter number of required values in the list: "))

for j in range( inp_1 ):

inp_2 = int(input("Enter the values: ")) #taking the values for the list

list1.append(inp_2)

list1.sort()

#sorting these values and taking the last term

print("Largest value is ", list1[-1])


#question 2

list1 = []

inp_1 = int(input("Enter number of values to be entered in the list: "))

for j in range( inp_1):

inp_2 = int(input("Enter the values ")) #entering the values

list1.append(inp_2)

list1.sort()

#sorting the list and taking the first term

print("Smallest element is:", list1[0])


#question 3

list1 = []

print(" Be prepared to enter 10 values for the list")

for i in range(10):

inp_1 = input("Enter the value ") #enetring the values

list1.append(inp_1)

list1.reverse() #using the built in .reverse() function to reverse it

print("The list in reverse order ", list1)


#question 4

print("Be prepared to enter 10 numbers!")

a=0

for i in range(10):

inp_1 = int(input("Enter a number: ")) #entering the numbers

a += inp_1

b = a/10

print("Sum is ", a)

print("Mean is ", b)
#question 5

import random

list1 = []

#using loop for random entry of numbers

for i in range(10):

x = random.randrange(10,99) #getting random numbers from 10 to 99

list1.append(x)

list2 = []

#checking for odd numbers

for j in list1:

if j % 2 != 0:

list2.append(j)

print("The Odd numbers python found are " , list2)


#question 6

list1 = []

inp_1 = int(input("Enter number of values to be entered in a list "))

#using for loop to add values

for i in range(inp_1):

inp_2= int(input("Enter values ")) #entering the values

list1.append(inp_2)

list2 = []

for j in list1:

if j not in list2: #checking for duplicacy

list2.append(j) #appending for list2 without duplicants

print("Corrected List")

print(list2)
#question 7

list1 = []

inp_1 = int(input("Enter the number of values to be enetred in the list "))

for i in range(inp_1):

inp_2 = input("Enter the value ") #entering the values

list1.append(inp_2)

list2 = ['']

a = 0 # making a counter and an empty list to test against

for j in list1:

if j in list2:

a += 1 #incrementing by 1 for each empty slot

if a == inp_1:

print("Empty List") #if all slots empty then empty list proved otherwise isn't

else:

print("Not Empty")
#question 8

x = []

inp_1 = int(input("Enter the number of values to be enetred in the list "))

for i in range(inp_1):

inp_2 = input("Enter the value ") #entering the values

x.append(inp_2)

x.remove(x[0]) #removing 0th value

x.remove(x[3]) #the initial 4th value is now 3rd after removal

x.remove(x[3]) #the initial 5th value is now 3rd after removal

#printing final list

print(x)
#question9

list1 = []

inp_1 = int(input("Enter the number of values to be entered in the list "))

for i in range(inp_1):

inp_2 = int(input("Enter the value ")) #entering the values

list1.append(inp_2)

list2 = []

#making a new list and asking for the number

inp_3 = int(input("Enter the number: "))

for i in list1:

if i > inp_3: #appending new list for items from than the given value

list2.append(i)

#displaying the result

print(list2)
#question10

list1 = []

list2 = []

#making empty lists for the names

while True:

x = input("Enter the names of the students of the first class:(press 1 to break)


")

if x == '1':

break #breaking the loop when names are finished

else:

list1.append(x) #taking records for the first class

while True:

y = input("Enter the names of the students of the second class:(press 1 to


break) ")

if y == '1':

break #breaking the loop when names are finished

else:

list2.append(y) #taking records for the second class

list3 = list1 + list2 #combining the list

list3.sort() #sorting it
#question 11

num = ['0','1','2','3','4','5','6','7','8','9'] #making a set of numbers for appending

list1 = []

#the list we need

while True:

x = input("Press 1 to start otherwise 2 to exit: ") #asking user for program


startup

if x== '1':

print()

print()

options = ['Press 1 to append',

'Press 2 to remove specified', #options for the menu program

'Press 3 to remove all',

'Press 4 to count specified',

'Press 5 to sort',
'Press 6 to reverse',

'Press 7 to display']

for i in options:

print(i)

print()

print()

a = input("")

if a == '1':

inp_1 = input("Type what you intend to append: ")

if inp_1 in num:

f = int(inp_1) #this is for numerical data

list1.append(f)

else:

list1.append(inp_1) #this is for string data


elif a == '2':

inp_2 = input("Type what you intend to remove: ")

list1.remove(inp_2)

elif a == '3':

for i in list1:

list1.remove(i)

list1.remove(list1[0]) #these are to remove the remaining 2 values

list1.remove(list1[0])

elif a == '4':

inp_3 = input("Type what you intend to count: ")

a=0

for k in list1:

if inp_3 in list1:

a += 1

print('Number of occurances ',a)

elif a == '5':
inp_4 = input("Sort in ascending or descending?: ")

if inp_4 == 'ascending':

list1.sort()

else:

list1.sort(reverse = True)

elif a == '6':

list1.reverse()

inp_5 = input("Should the list be displayed?: ") #asking user for display of
data

if inp_5 == 'yes':

print(list1)

else:

continue

elif x == '2':

break #stopping the program when user wants to exit

You might also like