0% found this document useful (0 votes)
61 views10 pages

Class 11 - CS - Practical Assessment

The document provides 10 Python programs to solve various problems. The programs include generating patterns, calculating Fibonacci series, counting characters in a string, finding minimum and maximum values in a list, swapping even and odd elements in a list, searching an element in a list, creating and accessing a dictionary of student records, counting words starting with vowels, deleting and summing list elements, and solving a quadratic equation. The programs demonstrate basic Python concepts like loops, strings, lists, tuples, dictionaries, and math functions.
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)
61 views10 pages

Class 11 - CS - Practical Assessment

The document provides 10 Python programs to solve various problems. The programs include generating patterns, calculating Fibonacci series, counting characters in a string, finding minimum and maximum values in a list, swapping even and odd elements in a list, searching an element in a list, creating and accessing a dictionary of student records, counting words starting with vowels, deleting and summing list elements, and solving a quadratic equation. The programs demonstrate basic Python concepts like loops, strings, lists, tuples, dictionaries, and math functions.
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/ 10

Class 11 – Computer Science (083) PYTHON PROGRAMS

General instructions :-

 Write the following python programs in your CS copy.


 To be submitted on Practical exam day :- 10th Feb.’24

1 Generate the following pattern :

Program :-

for i in range(1,6):

for j in range(1,i+1):

print('*',end=' ')

print()

Output :-

**

***

****

*****

2 Write a program to display the n terms of a Fibonacci series.

0,1,1,2,3,5,8,13,21,34,55,89,144,233,….

Program :-

n=int(input("How many terms?"))

x,y=0,1
if n>=1:

print(x,end=',')

if n>=2:

print(y,end=',')

for i in range(3,n+1):

z=x+y

print(z,end=',')

x,y=y,z

Output :-

How many terms? 10

0,1,1,2,3,5,8,13,21,34

3 Write a program to count and display the number of vowels, consonants,


uppercase, lowercase characters in the string.

Program :-

astring=input("Enter a string:")

vow=cons=up=low=0

for ch in astring:

if ch.isalpha():

if ch.lower() in 'aeiou':

vow+=1

else:

cons+=1
if ch.islower():

low+=1

else:

up+=1

print("Vowels=",vow)

print("Consonants=",cons)

print("Lowercase=",low)

print("Uppercase=",up)

Output :-

Enter a string:CBSE AISSCE exam 2023-24

Vowels= 6

Consonants= 8

Lowercase= 4

Uppercase= 10

4 Find the largest and smallest number in a list/tuple.

Program :-

numbers=eval(input("Enter elements of a tuple/list:"))

print("Smallest element=",min(numbers))

print("Largest element=",max(numbers))
Output :-

Enter elements of a tuple/list:(5,63,14,2,44,85)

Smallest element= 2

Largest element= 85

5 Input a list of numbers and swap elements at the even location with the
elements at the odd location.

Program :-

numbers=eval(input("Enter a list of numbers:"))

if len(numbers)%2==0:

n=len(numbers)

else:

n=len(numbers)-1

for i in range(n):

if i%2==0:

numbers[i],numbers[i+1]=numbers[i+1],numbers[i]

print("Changed list=",numbers)

Output :-

Enter a list of numbers:[65,85,4,12,11,74,36]

Changed list= [85, 65, 12, 4, 74, 11, 36]


6 Input a list/tuple of elements, search for a given element in the list/tuple.

Program :-

numbers=eval(input("Enter a list/tuple of numbers:"))

ele=int(input("Enter search element:"))

if ele in numbers:

print("element found at position=",numbers.index(ele)+1)

else:

print("element not found!")

Output :-

Enter a list/tuple of numbers:[54,3,26,28,74,71,19]

Enter search element:74

element found at position= 5

7 Create a dictionary with the roll number, name and marks of n students in a
class and display the names of students who have scored marks above 75.

Program :-

# create a dictionary with rollno,name and marks

srecords=dict()

n=int(input("How many students?"))


for i in range(n):

rollno=int(input("Rollno.?"))

sname=input("Name of student?")

marks=float(input("Marks?"))

srecords[rollno]=(sname,marks)

# display records of students scored above 75

print("Students scoring above 75=>")

for rollno in srecords:

if srecords[rollno][1]>75:

print(srecords[rollno][0])

Output :-

How many students?5

Rollno.?1

Name of student?Sakshi

Marks?78

Rollno.?2

Name of student?Devansh

Marks?65

Rollno.?3
Name of student?Rohan

Marks?85

Rollno.?4

Name of student?Milind

Marks?64

Rollno.?5

Name of student?Manish

Marks?90

Students scoring above 75=>

Sakshi

Rohan

Manish

8 Write a program which takes a string as an argument, count and display the
occurrence of words starting with a vowel in the given string.

Program :-

text=input("Enter a string:")

words=text.split()

c=0

for x in words:

if x[0] in 'aeiouAEIOU':

c+=1
print("no.of words starting with vowel=",c)

output :-

Enter a string:the owner of this land is a wealthy person

no.of words starting with vowel= 4

9 Write a program to read elements of a list and do the following :-

i. Ask position of the element to be deleted and delete the element at the
desired position in the list.
ii. Print the sum of all elements.

Program :-

L=eval(input("Enter a list of elements:"))

pos=int(input("Enter position of element to be deleted:"))

# i. delete element at given position

print("element deleted=",L.pop(pos-1))

print("L=",L)

# ii. sum of all elements

print("sum of all elements=",sum(L))

Output :-

Enter a list of elements:[5,3,6,8,7,10]

Enter position of element to be deleted:2


element deleted= 3

L= [5, 6, 8, 7, 10]

sum of all elements= 36

10 Write a program to accept the coefficients of a Quadratic Equation 𝑎𝑥 2 + 𝑏𝑥 +


𝑐 = 0 (a,b,c) and calculate the roots.

Hint. Calculate Discriminant 𝐷 = 𝑏 2 − 4𝑎𝑐

If D=0, then roots are real and equal.

If D>0, then roots are real and distinct.

If D<0, then roots are imaginary.

−𝑏±√𝐷
Formula for calculation of roots = 2𝑎

Program :-

import math

a,b,c=int(input("Enter a:")),int(input("Enter b:")),int(input("Enter c:"))

d=b*b-4*a*c

if d<0:

print("Imaginary roots")

elif d==0:

r=-b/(2*a)

print("Real and equal roots=",r)

else:

r1=(-b+math.sqrt(d))/(2*a)

r2=(-b-math.sqrt(d))/(2*a)

print("Real and distinct roots=",r1,r2)


Output :-

Enter a:3

Enter b:2

Enter c:4

Imaginary roots

Enter a:2

Enter b:-5

Enter c:3

Real and distinct roots= 1.5 1.0

**************

You might also like