Modified 11th CBSE CS Practical
Modified 11th CBSE CS Practical
th
1.
Output:■ Input: Hello, Students!■ Output: Hello, Students!
I
n p u t aw elcome messa ge an d d isplay i t.
print(messa ge)
2.
Output:■ Input: 10, 20■ Output: 20 is greater; 10 is smaller.
num2=int
(input("Enter s econd number: "))
if num1>num2:
else:
#small er number c
od e
num1=int(input ("Enter first num ber:") )
num2=int
(input("Enter s econd number: "))
if num1<num2:
else:
3.
Output:■ Input: 5, 15, 10■ Output: The largest number is 15.
num1=i
nt(input ("Enter F irst Number"))
num2=in
t(input ("Enter S econd Numbe r"))
num3=i
nt(input ("Enter T hird Number "))
eli
f (num2 > num1 and n um2> num3):
print
("The Lar gest num ber is", num2)
else:
4.
Output:■ 11111■ 2222■ 333■ 44■ 5
for i i n ra
n ge (1,6):
print(i,end= "")
print()
5.
Output:■ Input: x=2, n=3■ Output: 2 + 4 + 8 = 14
w riteap rogra mtoin p u tthevalu eof xan d n an d p rin tthesu mof thef o ll ow in gseries.
sum = 0
for a in ran ge(1,n +1):
sum = sum + x ** a
6.
Output:■ Input: 28■ Output: 28 is a perfect number.■ Input: 153■ Output: 153 is an Armstrong number.■ Inp
print("2.an ar
mst ron g or a")
n=
in
t(input ("Ente r an y number"))
sum1 = 0
if(n%i == 0 ):
sum1 = sum 1 + i
if (sum1 == n):
else:
print("1: The n
umbe r
", n,"is not a per fect num be r!")
order = l en(str(n ))
sum= 0
temp = n
while temp>0:
digit = temp%10
temp// =10
if n == sum :
else:
print("2:The number",n
," is not an armstrong number")
k=n
temp=n
rev=0
while(k>0):
dig=k %10
rev=r ev*10+di g
k=k// 10
if(temp==r ev):
else:
7.
Output:■ Input: 17■ Output: 17 is prime.
fact=0
for a in ran ge(2, num):
if num%a==0:
fact+ =1
break
if fact= =0:
else:
8.
Output:■ Input: 5■ Output: 5th Fibonacci number is 5.
def fib(n):
if n <=1:
return 1
return fib(n
-
1) + fib(n
-
2)
p
os= int (input("ente r the posi ti on of fibonacci nu mber: ") )
print(fib(pos))
9.
Output:■ Input: 'Hello World'■ Output: Vowels: 3, Consonants: 7, Uppercase: 2, Lowercase: 8.
C
ou n t an d d isp lay th e n u mb er of vow els, con son an ts, u pp erca se, low ercase
ch aracte rs in strin g.
v=c=u =l=0
for i i n s:
if i.i salpha():
v+=1
else:
c
+=1
if i.i supper():
u+=1
if i.i slower():
l+=1
print("vow els: ",v)
10.
Output:■ Input: 'Madam'■ Output: The string is a palindrome. Converted: 'mADAM'.
if (string==strin g[ ::
-
1] ):
else:
11.
Output:■ Input: [12, 45, 2, 89, 33]■ Output: Max: 89, Min: 2.
f ind the largest/small es t n u mb er in a li st
.
lst =[]
lst .append(nu
mbers)
12.
Output:■ Input: [1, 2, 3, 4, 5, 6]■ Output: [2, 1, 4, 3, 6, 5]
I
n p u t a li st of n u mb ers an d sw ap elemen ts at t h e even location w ith th e ele men ts at
the od d location .
lst =[]
f
or n in ran ge (num):
lst .append(numbers)
print("List befo re sw aping: ",lst )
temp1=lst [ i]
temp2=lst [ i+1]
lst [ i] =temp2
13.
Output:■ Input: [10, 20, 30], Search: 20■ Output: Found at index 1.
I
n p u t a list/tup le of elemen ts, sear ch f or a given elemen t in the list/tup le.
print("P ro gr am t o input a li st/ tupl e of elements, s earch fo r a given element in t he li st/ tupl e")
li st=[]
li st.append(numbers)
length = l en(list )
element=int(input ( "Enter the element t o be se arch ed for: "))
if element==li st[ i] :
print(elemen
t, "fo und at i ndex ",i,"and posi t ion: ",i+1)
break
else:
14.
Output:■ Input: [5, 8, 1, 3]■ Output: Smallest: 1, Largest: 8.
I
n p u t a list/tup le of n umb e rs an d f ind the sma ll est and largest nu mb e r f rom the li st.
print(my
li st)
15.
Output:■ Input: {1: ['Alice', 80], 2: ['Bob', 70], 3: ['Charlie', 90]}■ Output: Alice, Charlie.
C
reat e a d iction ary w ith the roll nu mb er, n a me an d mark
s of n stud en ts in a class
an d
d isp lay th e n ames o f stud en tsw h oh ave scored mark s ab ove 75.
print("c reat e a dictionar y with t he roll num ber, na me and marks of n stude nts i n a class and
\
n ")
result ={}
print("ent e
r details o f s tudents no.",i+1)
print(result )
print(result [ student][ 0] )