Python Code-Based Exam Practice
Questions
1. Basic Python Programs
1. Write a Python program to check if a number is even or odd.
2. Write a Python program to find the largest of three numbers.
3. Write a Python program to check if a given number is prime.
4. Write a Python program to reverse a number.
5. Write a Python program to calculate the factorial of a number.
2. String and List-Based Programs
6. Write a program to count the number of vowels in a given string.
7. Write a Python program to check if a string is a palindrome.
8. Write a program to swap consecutive elements in a list.
9. Write a Python program to find the second largest number in a list.
10. Write a Python program to merge two dictionaries into one.
3. Loop-Based and Pattern Printing Programs
11. Write a Python program to print the Fibonacci series up to N terms.
12. Write a program using nested loops to print a multiplication table.
13. Write a Python program to print a pyramid pattern using stars.
14. Write a program that prints all prime numbers in a given range.
15. Write a Python program to generate Pascal's Triangle up to N rows.
4. Dictionary and Tuple-Based Programs
16. Write a Python program to count the frequency of each character in a string.
17. Write a program to check if two given strings are anagrams.
18. Write a Python program to sort a dictionary by values in ascending and descending
order.
19. Write a program to split a list into two halves and store them in separate lists.
20. Write a Python program to find the sum of values in a dictionary.
5. File Handling and Functions
21. Write a program to read a file and count the number of words in it.
22. Write a Python function to check if a number is an Armstrong number.
23. Write a Python program to implement a simple calculator using functions.
24. Write a Python function to convert all uppercase letters in a string to lowercase and
vice versa.
25. Write a Python program to find and replace a word in a text file.