0% found this document useful (0 votes)
14 views14 pages

Modified 11th CBSE CS Practical

The document contains a series of programming exercises designed for 11th standard CBSE students, focusing on basic input/output operations, conditional statements, loops, and data structures in Python. Each exercise includes sample input and output, along with code snippets to solve specific problems such as finding the largest number, checking for prime numbers, and manipulating lists. The exercises aim to enhance students' understanding of fundamental programming concepts and their application.
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)
14 views14 pages

Modified 11th CBSE CS Practical

The document contains a series of programming exercises designed for 11th standard CBSE students, focusing on basic input/output operations, conditional statements, loops, and data structures in Python. Each exercise includes sample input and output, along with code snippets to solve specific problems such as finding the largest number, checking for prime numbers, and manipulating lists. The exercises aim to enhance students' understanding of fundamental programming concepts and their application.
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/ 14

11

th

S tan dard C B S E Practi cal

1.
Output:■ Input: Hello, Students!■ Output: Hello, Students!

I
n p u t aw elcome messa ge an d d isplay i t.

message= input ( "Enter yo ur welcome mess a ge: ")

print(messa ge)

2.
Output:■ Input: 10, 20■ Output: 20 is greater; 10 is smaller.

In p u t tw on u mb ers an d d isp lay th e larger/ sma ll er n u mb er.

#larger numbe r code

num1=int(input ("Enter first num ber:") )

num2=int
(input("Enter s econd number: "))

if num1>num2:

print(num1,"is gre ater ")

else:

print(num2,"is gre ater ")

#small er number c
od e
num1=int(input ("Enter first num ber:") )

num2=int
(input("Enter s econd number: "))

if num1<num2:

print(num1,"is s maller ")

else:

print(num2,"is s maller ")

3.
Output:■ Input: 5, 15, 10■ Output: The largest number is 15.

In p u t th ree n u mb ers an d d isplay th e largest/ small est nu mb er.

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 "))

#C heck if first num ber is gr eate


r than rest of th e t
wo numbers.

if (num1> num2 and nu m1> num3):

print("The Lar gest num ber is", num1)


#C heck if S econd numbe r is gr eate
r than rest of th e two numbers.

eli
f (num2 > num1 and n um2> num3):

print
("The Lar gest num ber is", num2)

else:

print ("The Lar gest num ber is", num3)

4.
Output:■ 11111■ 2222■ 333■ 44■ 5

Gen rat e the f oll ow in gpattern s u sin g n ested loop

for i i n ra
n ge (1,6):

for j i n ran ge (i,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.

x = float(input ("Enter b a se number :" ))

n = int (input("Ente r the p ower : "))

sum = 0
for a in ran ge(1,n +1):

sum = sum + x ** a

print("sum o f the s eries i s ", sum )

6.
Output:■ Input: 28■ Output: 28 is a perfect number.■ Input: 153■ Output: 153 is an Armstrong number.■ Inp

Dete r min e w h ethe


r a n u mb er is a p erf ec t n u mb er
an ar ms tron g n u mb er
ora
p ali nd rome.

print("program to check whether a number is a


\
n 1.perfect number,")

print("2.an ar
mst ron g or a")

print("3. pali ndrome.


\
n ")

n=

in
t(input ("Ente r an y number"))

#for per fect num be r

sum1 = 0

for i i n ran ge (1,n):

if(n%i == 0 ):
sum1 = sum 1 + i

if (sum1 == n):

print("1: The numbe r ", n,"is a pe rfe ct num ber! ")

else:

print("1: The n
umbe r
", n,"is not a per fect num be r!")

#for Armst ron g number

#calculated the l en gth(nu mber of di git s)

order = l en(str(n ))

#int ializ e sum

sum= 0

#find the sum of the cube of each di git

temp = n

while temp>0:

digit = temp%10

sum +=digit **ord er

temp// =10

#disp la y the r esult

if n == sum :

print("2:The numbe r ",n ," is an a rmstrong numb e r")

else:
print("2:The number",n
," is not an armstrong number")

#for pali ndrome numbe r

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):

print("3:The numbe r ", n," is a pali ndrome ! ")

else:

print("3:The numbe r ", n," isn 't a pali ndrome! ")

7.
Output:■ Input: 17■ Output: 17 is prime.

In p u t a nu mb er an d ch eck if the nu mb er is a p rime or n ot nu mb er.

num=int(input ("Enter a n umber "))

fact=0
for a in ran ge(2, num):

if num%a==0:

fact+ =1

break

if fact= =0:

print(num, "is prim e ")

else:

print(num, "is not prime")

8.
Output:■ Input: 5■ Output: 5th Fibonacci number is 5.

d isp lay th e n thf ib on n aci n u mb er


.

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.

s=input ("Ente r an y strin g:")

v=c=u =l=0

for i i n s:

if i.i salpha():

if i.l ower() in 'a eiou ':

v+=1

else:

c
+=1

if i.i supper():

u+=1

if i.i slower():

l+=1
print("vow els: ",v)

print("conson ants: ",c )

print("uppe rcas e:",u )

print("lowe rcas e:",l)

10.
Output:■ Input: 'Madam'■ Output: The string is a palindrome. Converted: 'mADAM'.

In p u t a strin g and d eter min e w h ether it is a p ali n rome or n ot

con vert the case of


ch aracte rs in a st
rin g.

print("Input a string and determi ne wheth er it i s a pali ndrome or not;


\
n ")

print("conv ert the c ase of chara cters in a strin g.


\
n ")

string=input (("Enter a string:"))

if (string==strin g[ ::
-
1] ):

print("The st ring is a p ali ndrome")

else:

print("Not a p ali ndrome")

print("S trin g afte r conve r ti ng the c ase:",strin g.sw a pcase( ))

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 =[]

num=int(input ('How m an y numbers: '))

for n in ran ge (num):

numbers = int (input( 'E nter number ') )

lst .append(nu
mbers)

print("max im um element in t he li st i s:",max (lst))

print("mi nim um element in t he li st i s:",mi n(lst))

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 =[]

num=int(input ('How m an y numbers: '))

f
or n in ran ge (num):

numbers=int (input( 'Enternumber '))

lst .append(numbers)
print("List befo re sw aping: ",lst )

for i i n ran ge (0,num,2):

temp1=lst [ i]

temp2=lst [ i+1]

lst [ i] =temp2

lst [ i+1] =temp1

print("List afte r swapin g: ",lst )

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=[]

num=int(input ("How ma n y numbe rs in the lis t: "))

for n in ran ge (num):

numbers=int (input("E nter number "))

li st.append(numbers)

print("the entered li st i s", li st)

length = l en(list )
element=int(input ( "Enter the element t o be se arch ed for: "))

for i i n ran ge (0,len gth):

if element==li st[ i] :

print(elemen
t, "fo und at i ndex ",i,"and posi t ion: ",i+1)

break

else:

print(element, " is no t found!!! ")

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.

m yli st=[ 20,100,20,1,10]

m yli st.s ort()

print(my
li st)

print("smallest elem ent i s :",m yli st[ 0] )

print("lar gest element is : ",m yli st[


-
1] )

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 ")

print("displ a y the nam es of students w


ho have sco red marks abo ve 75 ")

result ={}

n= int (input("ent er numb er of students: "))

for i i n ran ge (n):

print("ent e
r details o f s tudents no.",i+1)

rno=int (input("roll no: "))

name=input ( "name: ")

marks=int (input("m ar ks:"))

result [ rno] =[ name,marks]

print(result )

for student i n result :

if result [ student][ 1] >75:

print(result [ student][ 0] )

You might also like