CBSE Class 11 Computer Science Practical File, Python Programs with Output
The CBSE Class 11 Computer Science (083) practical carries 30 marks, and the report file needs programs covering Python fundamentals, strings, lists, dictionaries and files. Every program below was run before it was published and the output you see is the output it actually produced.
1. Check whether a number is prime
num = 29
if num < 2:
print(num, "is not prime")
else:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print(num, "is not prime")
break
else:
print(num, "is prime")29 is prime
2. Sum of the digits of a number
num = 4829
total = 0
n = num
while n > 0:
total += n % 10
n //= 10
print("Number:", num)
print("Sum of digits:", total)Number: 4829 Sum of digits: 23
3. Print the Fibonacci series up to n terms
n = 10
a, b = 0, 1
series = []
for _ in range(n):
series.append(a)
a, b = b, a + b
print("First", n, "Fibonacci numbers:")
print(series)First 10 Fibonacci numbers: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
4. Count vowels, consonants, digits and spaces in a string
text = "Kwickprep Class 11 Computer Science"
vowels = consonants = digits = spaces = 0
for ch in text:
if ch.isalpha():
if ch.lower() in "aeiou":
vowels += 1
else:
consonants += 1
elif ch.isdigit():
digits += 1
elif ch == " ":
spaces += 1
print("String :", text)
print("Vowels :", vowels)
print("Consonants:", consonants)
print("Digits :", digits)
print("Spaces :", spaces)String : Kwickprep Class 11 Computer Science Vowels : 9 Consonants: 20 Digits : 2 Spaces : 4
5. Find the largest and smallest element in a list
marks = [67, 92, 45, 88, 73, 51]
largest = smallest = marks[0]
for m in marks:
if m > largest:
largest = m
if m < smallest:
smallest = m
print("List :", marks)
print("Largest :", largest)
print("Smallest:", smallest)List : [67, 92, 45, 88, 73, 51] Largest : 92 Smallest: 45
6. Linear search in a list
roll = [11, 24, 37, 42, 58, 63]
target = 42
found = -1
for i in range(len(roll)):
if roll[i] == target:
found = i
break
if found == -1:
print(target, "not found")
else:
print(target, "found at index", found)42 found at index 3
7. Count the frequency of each word in a sentence
sentence = "the exam is the same the syllabus is not"
freq = {}
for word in sentence.split():
freq[word] = freq.get(word, 0) + 1
for word in sorted(freq):
print(word, ":", freq[word])exam : 1 is : 2 not : 1 same : 1 syllabus : 1 the : 3
8. Write to a text file and read it back
with open("notes.txt", "w") as f:
f.write("Computer Science 083\n")
f.write("Informatics Practices 065\n")
with open("notes.txt", "r") as f:
for line in f:
print(line.strip())Computer Science 083 Informatics Practices 065
9. Count the lines and words in a text file
with open("essay.txt", "w") as f:
f.write("A stack is a LIFO structure.\n")
f.write("A queue is a FIFO structure.\n")
f.write("Both are linear data structures.\n")
lines = words = 0
with open("essay.txt") as f:
for line in f:
lines += 1
words += len(line.split())
print("Lines:", lines)
print("Words:", words)Lines: 3 Words: 17
10. Sort a list using bubble sort
data = [45, 12, 78, 33, 9, 61]
n = len(data)
for i in range(n - 1):
for j in range(n - 1 - i):
if data[j] > data[j + 1]:
data[j], data[j + 1] = data[j + 1], data[j]
print("Sorted list:", data)Sorted list: [9, 12, 33, 45, 61, 78]
11. Build a dictionary of student marks and find the topper
marks = {"Aarav": 78, "Diya": 91, "Ishaan": 84, "Meera": 91}
top = max(marks.values())
toppers = [name for name in marks if marks[name] == top]
print("Marks :", marks)
print("Highest:", top)
print("Topper :", ", ".join(sorted(toppers)))Marks : {'Aarav': 78, 'Diya': 91, 'Ishaan': 84, 'Meera': 91}
Highest: 91
Topper : Diya, Meera12. Check whether a string is a palindrome
for word in ["level", "python", "madam"]:
clean = word.lower()
print(word, "->", "Palindrome" if clean == clean[::-1] else "Not a palindrome")level -> Palindrome python -> Not a palindrome madam -> Palindrome
Get the full practical-file pack, free
Every program, the exact practical-file format your school expects, and the viva questions that come up most — sent on WhatsApp.
Get it on WhatsApp Book a free demo classRelated: Class 11 CS syllabus · Try the code in the Python Playground · Class 12 CS practical file
Stuck on your practical file or the viva?
Kajal Ma'am has been teaching these practicals since 2004. See a real class first — no payment, no commitment.
Book a free demo class
