0% found this document useful (0 votes)
8 views15 pages

Cs Practical

cs class 11th

Uploaded by

pavitr.hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Cs Practical

cs class 11th

Uploaded by

pavitr.hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Mayank Mayur CS Practical file 2024-25 Class-11th-C

actical-file-2024-25-class-11th-c

February 17, 2025

[2]: # Q1-WAP to calculate the area and cicumference of a circle if radius is given
# Ans:-

r=7
�=3.14
a=�*r*r
c=2*�*r
print("The area of the circle is",a)
print('The circumfernce of the circle is',c)

The area of the circle is 153.86


The circumfernce of the circle is 43.96

[1]: #Q2-WAP to make a simple calculator that reads two numbers and an operator. On␣
↪selection of an operator, perform operation and print the result

#Ans-

a=int(input("enter 1st number: "))


b=int(input("enter 2nd number: "))
op=input("enter (+.-,/,//,*,**,%)")

if op=='+':
print("Result is",a+b)
elif op=='-':
print("Result is",a-b)
elif op=='/':
print("Result is",a/b)
elif op=='//':
print("Result is",a//b)
elif op=='*':
print("Result is",a*b)
elif op=='**':
print("Result is",a**b)
elif op=='%':
print("Result is",a%b)
else:
print("invalid Chacracter please try again")

1
enter 1st number: 2
enter 2nd number: 10
enter (+.-,/,//,*,**,%)**
Result is 1024

[12]: #Q3 You are driving a little too fast and the police officer stops you and␣
↪issues a ticket. Write code to compute the result, encoded as an integer␣

↪value: 0=no ticket, 1=small ticket, 2=big ticket.

#If speed is 60 or less, the result is 0. If speed is between 61 and 80␣


↪inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless␣

↪it is your birthday, on that day, your speed can be 5 higher in all cases.␣

↪WAP to model above scenario.

#Ans-

bday=input("Is your birthday today!! enter y/n : ")


speed=int(input("enter the speed of your vehicle you good sir : "))

if bday=="y":
if speed<65:
Ticket=0
elif (speed>65 and speed<85):
Ticket=1
elif speed>85:
Ticket=2

else :
if speed<60:
Ticket=0
elif speed>60 and speed<80:
Ticket=1
elif speed>80:
Ticket=2

if Ticket==0:
print("The speed is =", speed ,'and bday is =', bday ,", So No ticket for␣
↪you")

elif Ticket==1:
print("The speed is =", speed ,'and bday is =', bday ,", Small ticket")
elif Ticket==2:
print("The speed is =", speed ,'and bday is =', bday ,", Big ticket")

Is your birthday today!! enter y/n : y


enter the speed of your vehicle you good sir : 56
The speed is = 56 and bday is = y , So No ticket for you

2
[1]: #Q6 Write a program which will find all such numbers which are divisible by 7␣
↪but are not multiple of 5, between 2000 and 3200 (both included).

#The numbers obtained should be printed in a comma-separated sequence on a␣


↪single line.

#ans:-

for x in range (2000,3201):


if (x%7==0 and x%5!=0):
print(x,end=", ")

2002, 2009, 2016, 2023, 2037, 2044, 2051, 2058, 2072, 2079, 2086, 2093, 2107,
2114, 2121, 2128, 2142, 2149, 2156, 2163, 2177, 2184, 2191, 2198, 2212, 2219,
2226, 2233, 2247, 2254, 2261, 2268, 2282, 2289, 2296, 2303, 2317, 2324, 2331,
2338, 2352, 2359, 2366, 2373, 2387, 2394, 2401, 2408, 2422, 2429, 2436, 2443,
2457, 2464, 2471, 2478, 2492, 2499, 2506, 2513, 2527, 2534, 2541, 2548, 2562,
2569, 2576, 2583, 2597, 2604, 2611, 2618, 2632, 2639, 2646, 2653, 2667, 2674,
2681, 2688, 2702, 2709, 2716, 2723, 2737, 2744, 2751, 2758, 2772, 2779, 2786,
2793, 2807, 2814, 2821, 2828, 2842, 2849, 2856, 2863, 2877, 2884, 2891, 2898,
2912, 2919, 2926, 2933, 2947, 2954, 2961, 2968, 2982, 2989, 2996, 3003, 3017,
3024, 3031, 3038, 3052, 3059, 3066, 3073, 3087, 3094, 3101, 3108, 3122, 3129,
3136, 3143, 3157, 3164, 3171, 3178, 3192, 3199,

[2]: #Q7 Develop a program to classify students amongst various categories as per␣
↪their age entered. Read age of N students and count no of students falling␣

↪in each category

#Ans-

n=int(input("Enter the number of People = "))


gpa=gpb=gpc=gpd=gpe=0
for x in range(1,n+1):
age=int(input("Enter the age of the person = "))
if age>=12 and age<15:
gpa+=1
elif age>=15 and age<17:
gpb+=1
elif age>=17 and age<19:
gpc+=1
elif age<12:
gpd+=1
else:
gpe+=1
print("People in Group A: 12 yrs and above but less than 15 yrs =",gpa)
print("People in Group B: 15 yrs and above but less than 17 yrs =",gpb)
print("People in Group C: 17 yrs and above but less than 19 yrs =",gpc)
print("People in Group D: Less than 12 yrs =",gpd)
print("People in Group E: Above 19 yrs =",gpe)

3
Enter the number of People = 5
Enter the age of the person = 10
Enter the age of the person = 13
Enter the age of the person = 78
Enter the age of the person = 16
Enter the age of the person = 18
People in Group A: 12 yrs and above but less than 15 yrs = 1
People in Group B: 15 yrs and above but less than 17 yrs = 1
People in Group C: 17 yrs and above but less than 19 yrs = 1
People in Group D: Less than 12 yrs = 1
People in Group E: Above 19 yrs = 1

[1]: #q4 Write a program to print following patterns upto N lines


#i)
n=int(input("enter a number = "))
for i in range(1,n+1):
for x in range(1,i+1):
print("*",end=" ")
print()

enter a number = 5
*
* *
* * *
* * * *
* * * * *

[2]: #q4 Write a program to print following patterns upto N lines


#ii]

n=int(input("enter a number = "))


for i in range(1,n+1):
print(" "*(n-i),end="")
print("*"*i,end="")
print()

enter a number = 6
*
**
***
****
*****
******

[2]: #Q8.Write a program to find if a number entered is a palindrome or not

n=int(input("enter a number"))
rev=0

4
x=n
while(n>0):
digit=n%10
rev=rev*10+digit
n=n//10
if rev==x:
print(x,"is a palindrome")
else:
print(x,"is not a plaindrome")

enter a number1234
1234 is not a plaindrome
9. According to a study, the approximate level of Intelligence of a person can be calculated using
the following formula: i=2(y+0.5x) Write program, which will produce a table of values of i, y and
x where y varies from 1 to 6 and for each value of y , x varies from 5.5 to 12.5 in steps of 0.5.
[1]: for y in range(1,7):
for x in range(5,13):
x+=0.5
print("value of the y = ",y)
print("value of the x = ",x)
i=2*(y+(0.5*x))
print("value of the i = ",i)
print()

value of the y = 1
value of the x = 5.5
value of the i = 7.5

value of the y = 1
value of the x = 6.5
value of the i = 8.5

value of the y = 1
value of the x = 7.5
value of the i = 9.5

value of the y = 1
value of the x = 8.5
value of the i = 10.5

value of the y = 1
value of the x = 9.5
value of the i = 11.5

value of the y = 1
value of the x = 10.5

5
value of the i = 12.5

value of the y = 1
value of the x = 11.5
value of the i = 13.5

value of the y = 1
value of the x = 12.5
value of the i = 14.5

value of the y = 2
value of the x = 5.5
value of the i = 9.5

value of the y = 2
value of the x = 6.5
value of the i = 10.5

value of the y = 2
value of the x = 7.5
value of the i = 11.5

value of the y = 2
value of the x = 8.5
value of the i = 12.5

value of the y = 2
value of the x = 9.5
value of the i = 13.5

value of the y = 2
value of the x = 10.5
value of the i = 14.5

value of the y = 2
value of the x = 11.5
value of the i = 15.5

value of the y = 2
value of the x = 12.5
value of the i = 16.5

value of the y = 3
value of the x = 5.5
value of the i = 11.5

value of the y = 3
value of the x = 6.5

6
value of the i = 12.5

value of the y = 3
value of the x = 7.5
value of the i = 13.5

value of the y = 3
value of the x = 8.5
value of the i = 14.5

value of the y = 3
value of the x = 9.5
value of the i = 15.5

value of the y = 3
value of the x = 10.5
value of the i = 16.5

value of the y = 3
value of the x = 11.5
value of the i = 17.5

value of the y = 3
value of the x = 12.5
value of the i = 18.5

value of the y = 4
value of the x = 5.5
value of the i = 13.5

value of the y = 4
value of the x = 6.5
value of the i = 14.5

value of the y = 4
value of the x = 7.5
value of the i = 15.5

value of the y = 4
value of the x = 8.5
value of the i = 16.5

value of the y = 4
value of the x = 9.5
value of the i = 17.5

value of the y = 4
value of the x = 10.5

7
value of the i = 18.5

value of the y = 4
value of the x = 11.5
value of the i = 19.5

value of the y = 4
value of the x = 12.5
value of the i = 20.5

value of the y = 5
value of the x = 5.5
value of the i = 15.5

value of the y = 5
value of the x = 6.5
value of the i = 16.5

value of the y = 5
value of the x = 7.5
value of the i = 17.5

value of the y = 5
value of the x = 8.5
value of the i = 18.5

value of the y = 5
value of the x = 9.5
value of the i = 19.5

value of the y = 5
value of the x = 10.5
value of the i = 20.5

value of the y = 5
value of the x = 11.5
value of the i = 21.5

value of the y = 5
value of the x = 12.5
value of the i = 22.5

value of the y = 6
value of the x = 5.5
value of the i = 17.5

value of the y = 6
value of the x = 6.5

8
value of the i = 18.5

value of the y = 6
value of the x = 7.5
value of the i = 19.5

value of the y = 6
value of the x = 8.5
value of the i = 20.5

value of the y = 6
value of the x = 9.5
value of the i = 21.5

value of the y = 6
value of the x = 10.5
value of the i = 22.5

value of the y = 6
value of the x = 11.5
value of the i = 23.5

value of the y = 6
value of the x = 12.5
value of the i = 24.5

10. WAP to print the sum of n terms of the following series - A) x+ x2/2 + x3/3 + x4/4 +....+xn/n

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


n=int(input("Enter the value of n"))
result=0
for i in range(1,n+1):
y=(x**i)/i
result+=y
print("The result is",result)

Enter the value of x1


Enter the value of n2
The result is 1.5
B) 1/ (sqrt(2) + 2 / sqrt(3) + 3/ sqrt(4) +.......n/sqrt(n+1)

[5]: n=int(input("enter the value of n"))


result=0
for i in range(1,n+1):
y=(i/((i+1)**1/2))
result+=y
print("The result is",result)

9
enter the value of n3
The result is 3.833333333333333
11. Read two strings and check if string1 is prefix, postfix or nothing from the string2.
[4]: s=input("Enter the main string - ")
sub=input("enter the substring - ")
news=""
for i in range(len(sub)):
x=s[i]
news+=x
if news==sub:
print(sub,"is the prefix of",s)
else:
print(sub,"is not the prefix of",s)

Enter the main string - evergreen


enter the substring - ever
ever is the prefix of evergreen
12. Write a program to read a string and print i)Frequency of all characters ii) Word of highest
length iii) The string in title case iv) Read full name as a string and print only the initial letters
except last name Eg- Enter name: Mohan Das Karam Chand Gandhi, O/p M D K C Gandhi.

[5]: #I)Frequency
s=input("enter the string - ")
print("Frequency of the letters")
news=""
for i in range(len(s)):
if s[i] not in news:
news+=s[i]
print(s[i],"comes",s.count(s[i]),"times")
print()
print()

#II)Highest length
print("Highest length")
l=s.split()
print(l)
high=l[0]
y=0
for x in l:
if len(high)<len(x):
high=x
print(high)
print()
print()

#III)Title case

10
print("Title case")
print(s.title())
print()
print()

#IV)M D K C Gandhi
print("M D K C Gandhi")
g=s.title()
o=g.split()
print(o)
name=""
for i in range(len(o)-1):
name+= o[i][0].upper()+" "
print(name+o[-1])

enter the string - mohan das karam chand gandhi


Frequency of the letters
m comes 2 times
o comes 1 times
h comes 3 times
a comes 6 times
n comes 3 times
comes 4 times
d comes 3 times
s comes 1 times
k comes 1 times
r comes 1 times
c comes 1 times
g comes 1 times
i comes 1 times

Highest length
['mohan', 'das', 'karam', 'chand', 'gandhi']
gandhi

Title case
Mohan Das Karam Chand Gandhi

M D K C Gandhi
['Mohan', 'Das', 'Karam', 'Chand', 'Gandhi']
M D K C Gandhi
13. In Cryptography, a Caesar cipher is a very simple encryption techniques in which each letter
in the plain text is replaced by a letter some fixed number of positions down the alphabet list in a

11
cyclic manner. For example, with a shift of 3, A would be replaced by D, B would become E, and
so on. The method is named after Julius Caesar, who used it to communicate with his generals.
ROT-13 (”rotate by 13 places”). Create menu driven program to encrypt and decrypt which takes
in a string and rotation (rotate by n places) and encrypts the string then decrypts the string. The
program should be menu driven. Also if rotation is not specified then the encryption should take
place by 13.
[9]: s=input("Enter a string: ")
rotno=input('Do you want to give a specific rotation number y/n: ')

if rotno=='y':
n=int(input("enter the rotation number: "))
elif rotno=='n':
n=13
choice=int(input("Choose to 1.Encrypt or 2.Decrypt: "))
newcode=''

if choice==1:
for i in s:
x=ord(i)+n
if((x>90 and x<97) or (x>122)):
x=x-26
newcode+=chr(x)
print()
print(s,"is encryted to",newcode)
elif choice==2:
for i in range(len(s)):
x=ord(s[i])-n
if((x<65) or (x<97 and x>90)):
x=x+26
newcode+=chr(x)
print()
print(s,"is decryted to",newcode)

Enter a string: ZOOM


Do you want to give a specific rotation number y/n: y
enter the rotation number: 3
Choose to 1.Encrypt or 2.Decrypt: 1

ZOOM is encryted to CRRP


5.WAP that reads n digit number. After reading the number, compute and display the sum of the
odd positioned digits, multiply all even positioned digits and add these two numbers.
[4]: n=int(input("enter a number = "))
s=str(n)
sumodd=0
prodeven=1

12
for i in range(len(s)):
if i%2==0:
prodeven*=int(s[i])
else:
sumodd+=int(s[i])
result=prodeven+sumodd
print("The result is",result)

enter a number = 1234


The result is 9
14. Write a program which takes 2 digits, X, Y as input and generates a 2-dimensional array. The
element value in thei-th row and j-th column of the array should be i*j.
[5]: r=int(input("enter rows:"))
c=int(input("enter cols:"))
l=[]
for i in range(r):
k=[]
for j in range(c):
k.append(i*j)
l.append(k)
print(l)

for i in range(r):
for j in range(c):
print(l[i][j],end=' ')
print()

enter rows:3
enter cols:5
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
16. Write a program to find the second largest number in a given list.
[1]: n=int(input("enter the number of elements:"))
l=[int(input("Enter a number:")) for i in range(n)]
l.sort()
print(l)
print(f'the second largest number is {l[-2]}')

enter the number of elements:4


Enter a number:3
Enter a number:43
Enter a number:12
Enter a number:65

13
[3, 12, 43, 65]
the second largest number is 43
15. Write a program to generate a random 6 digits secure OTP. The digits should not repeat.
[ ]: import random

n=random.randint(0,9)
s=""
while (len(s)!=6):
if str(n) not in s:
s+=str(n)
print(f"Random OTP is {s}")

17. Write a program that takes a list of words and creates a dictionary with word as the
key and number of occurrences of the word as the value. For example if list is given as
[’the’,’of’,’an’,’is’,’an’,’the’] Then the dictionary should be d=’the’:2,’of’:1,’an’:2,’is’:1

[4]: import collections


s=input('Enter words with spaces: ')
l=s.split()
d=dict(collections.Counter(l))
print(d)

Enter words with spaces: the of an is an the


{'the': 2, 'of': 1, 'an': 2, 'is': 1}
19. Write a program to create a dictionary of names of flowers as keys and the colours in which
they exist as values in tuples, for example D=’rose’:(’red’,’black’,’pink’),’lily’:(’white’,’violet’) . Now
write a code to print a) The flower which exists in maximum number of colors b) The colour in
which most of the flowers exist
[14]: #A
d={'rose':('red','black','pink','white'),'lily':('white','violet'),'tulips':
↪('pink','yellow','purple','white'),'daisy':('red','orange','yellow')}

max=0
for i in d:
if len(d[i])>=max:
max = len(d[i])
flower = i
else:
max = max
print(f"Flower with the maximum colours is {flower} and it has {max} no. of␣
↪colours.")

#B
v=list(d.values())
d={}
for i in v:
for j in i:

14
if j not in d:
d[j]=i.count(j)
else:
d[j]+=i.count(j)
max=0
color=""
for i in d:
if d[i]>max:
max=d[i]
color=i

print(color,"is the color which is most flowers exist in")

Flower with the maximum colours is tulips and it has 4 no. of colours.
white is the color which is most flowers exist in
20. There are 36 possible combinations if we throw two dice. A simple pair of loops over range
(6) +1 will enumerate all combinations. The sum of the two dice is more interesting than the
actual combination. Create a dictionary of all combinations, using the sum of numbers on the two
dice as the key. Each value of dictionary will be a tuple with all possible combination. 12:[(6,6)],
11:((6,5),(5,6))……

[13]: l=[]
d={}
for i in range(1,7):
for j in range(1,7):
l.append((i,j))
for x in l:
if sum(x) not in d:
d[sum(x)]=[(x)]
else:
d[sum(x)].append((x))
print(d)

{2: [(1, 1)], 3: [(1, 2), (2, 1)], 4: [(1, 3), (2, 2), (3, 1)], 5: [(1, 4), (2,
3), (3, 2), (4, 1)], 6: [(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)], 7: [(1, 6),
(2, 5), (3, 4), (4, 3), (5, 2), (6, 1)], 8: [(2, 6), (3, 5), (4, 4), (5, 3), (6,
2)], 9: [(3, 6), (4, 5), (5, 4), (6, 3)], 10: [(4, 6), (5, 5), (6, 4)], 11: [(5,
6), (6, 5)], 12: [(6, 6)]}

[ ]:

15

You might also like