Computer Science
Grade 12 Python – Unit Test Practice Set (15 Questions)
Topics Covered:
● Strings
● Lists
● Tuples
● Dictionaries
● Functions
● Exception Handling
Q1. String Operations
Write a Python program to:
● Input a string from the user.
● Print:
○ Total number of characters
○ Number of vowels
○ Reverse of the string
○ String in uppercase.
Q2. List Manipulation
Accept 10 integers from the user and store them in a list.
Display:
● Largest number
● Smallest number
● Sum of all elements
● Average of the list.
Q3. List Processing
Given the list:
numbers = [12, 45, 67, 12, 89, 45, 23, 90]
Write a program to:
● Remove duplicate elements.
● Sort the list in descending order.
● Print only even numbers.
Q4. Tuple Operations
Create a tuple of 8 city names.
Write a program to:
● Print the first and last city.
● Count how many times a city entered by the user appears.
● Display the tuple in reverse order.
Q5. Dictionary Basics
Create a dictionary containing student details:
Roll No
Name
Marks
Grade
Display all keys, all values, and all key-value pairs using a loop.
Q6. Dictionary Application
Store marks of five students in a dictionary.
Example:
{
"Amit":78,
"Riya":91,
"Rahul":65
}
Write a program to:
● Display the topper's name.
● Calculate the average marks.
● Display students scoring above 75.
Q7. Functions
Write a function:
factorial(n)
that returns the factorial of a number.
Call the function for a number entered by the user.
Q8. Functions with Return Value
Write a function:
isPalindrome(word)
that returns True if the given string is a palindrome, otherwise False.
Q9. Functions + List
Write a function
countEven(lst)
which accepts a list and returns the number of even elements present in it.
Q10. String Functions
Write a program to:
● Input a sentence.
● Count the number of words.
● Count the number of uppercase letters.
● Replace every space with '*'.
Q11. Exception Handling
Write a program that accepts two integers and performs division.
Handle:
● Division by zero
● Invalid input
Display appropriate error messages.
Q12. Exception Handling with List
Create a list containing five numbers.
Ask the user for an index and print the element.
Handle:
● Invalid index
● Invalid input
using exception handling.
Q13. Mixed Question (List + Dictionary)
Given
students = {
"Amit":[78,81,90],
"Riya":[90,95,88],
"Rahul":[67,72,70]
}
Write a program to display:
● Average marks of every student.
● Student with highest average.
● Students whose average is above 80.
Q14. Functions + Exception Handling
Write a function
safeDivision(a,b)
that returns the quotient.
Use exception handling inside the function to handle division by zero and invalid inputs.
Q15. Comprehensive Programming Question
Write a menu-driven program using functions.
1. Reverse a String
2. Find Maximum in a List
3. Search a Key in Dictionary
4. Find Factorial
5. Exit
The program should repeatedly display the menu until the user chooses Exit.