Python Programming Question Bank
1. Expressions and Data Types
1. Write a program to perform basic arithmetic operations (addition, subtraction,
multiplication, division) on two numbers.
2. Write a program to display the type of variable (integer, float, string).
3. Write a program to calculate the area of a rectangle (Area = length × width).
4. Write a program that accepts a user’s age and prints whether the user is eligible to vote
(18+).
2. Strings and Variables
5. Write a program that accepts a user's name and prints a greeting message.
6. Write a program that takes two strings and concatenates them.
7. Write a program to replicate a string 5 times using the * operator.
8. Write a program to swap the values of two variables.
3. Flow Control – Conditions and Boolean Logic
9. Write a program to check whether a number is even or odd.
10. Write a program that checks if a number is positive, negative, or zero.
11. Write a program to find the greatest of three numbers.
12. Write a program to check whether a character is a vowel or consonant.
4. Boolean and Comparison Operators
13. Write a program using comparison operators to compare two numbers and display
appropriate messages.
14. Write a program using logical operators to check if a number is between 10 and 50.
15. Write a program using not, and, and or operators with Boolean expressions.
5. Flow Control – Loops
16. Write a program to print numbers from 1 to 10 using a while loop.
17. Write a program to calculate the factorial of a number using a while loop.
18. Write a program to display the sum of even numbers between 1 and 100.
19. Write a program to print the multiplication table of a number entered by the user.
6. Importing Modules and sys.exit()
20. Write a program to generate and print a random number between 1 and 100.
21. Write a program that uses sys.exit() to terminate the program based on user input.
22. Write a program to find the square root of a number using the math module.
7. Functions and Parameters
23. Write a function to add two numbers and return the result.
24. Write a function that checks whether a number is prime.
25. Write a program with a function to find the factorial of a number.
26. Write a function that accepts a name as a parameter and prints a personalized welcome
message.
27. Write a function with default parameters to print user info (name, age, city).
28. Write a program to demonstrate the difference between local and global variables.
8. The global Statement
29. Write a program with a global variable and modify it inside a function using the global
keyword.
9. Exception Handling
30. Write a program to handle divide-by-zero exception.
31. Write a program to catch ValueError if the user enters non-integer input.
32. Write a program to accept a number from the user and print its reciprocal using
exception handling.
10. Project-Based Program – Guess the Number Game
33. Write a program to generate a random number between 1 and 10. Let the user guess the
number until they get it right.
34. Modify the program to limit the number of guesses to 5 and display a message after each
guess.
35. Add exception handling to the game to ensure it doesn’t crash if the user inputs a non-
integer value.
Advanced Thinking / Bonus Tasks
36. Write a program to simulate a simple calculator using functions (+, -, *, /).
37. Write a program to check if a string is a palindrome.
38. Write a program that accepts marks of 5 subjects and displays total, average, and grade.