Variables and Data Types (Easy to Intermediate)
1. Define a variable x and assign it the value 10. Print its type.
2. Write a Python program to swap the values of two variables.
3. What is the output of the following code?
x = 5.5
y = int(x)
print(y)
4. Write a program to check whether a given number is an integer or a float.
5. Create a variable name and assign your name to it. Print a greeting using this variable.
Lists (Easy to Advanced)
6. Create a list of 5 fruits and print the second fruit.
7. Write a program to append an element to a list.
8. Remove the third element from a list of numbers [10, 20, 30, 40, 50].
9. Write a Python program to reverse a list without using the reverse() function.
10. Write a program to find the maximum and minimum elements in a list.
Strings (Easy to Advanced)
11. Write a program to find the length of a string.
12. Extract the first 5 characters from the string "Hello, World!".
13. Write a program to check if a given string is a palindrome.
14. Replace all occurrences of "Python" with "Java" in the string "Python is awesome. Python is
fun.".
15. Count the number of vowels in a given string.
Tuples (Easy to Intermediate)
16. Create a tuple with numbers from 1 to 5.
17. Write a program to find the index of the number 3 in a tuple.
18. Can you modify a tuple after creation? Justify your answer.
19. Write a program to convert a list to a tuple.
20. Write a Python program to merge two tuples.
Dictionaries (Easy to Advanced)
21. Create a dictionary with three key-value pairs.
22. Write a program to add a new key-value pair to an existing dictionary.
23. Delete a key-value pair from a dictionary.
24. Write a program to retrieve all keys from a dictionary.
25. Write a Python program to find the sum of all values in a dictionary.
If, Else, Elif, and Multiple If (Easy to Advanced)
26. Write a program to check if a number is positive, negative, or zero.
27. Write a program to find the largest of three numbers using nested if statements.
28. Check whether a given year is a leap year or not.
29. Write a program to check if a person is eligible to vote based on their age.
30. Write a program using multiple if statements to check whether a number is divisible by 2, 3,
and 5.
Logical and Relational Operators (Intermediate)
31. Write a program to check if a number lies between 10 and 20 using logical operators.
32. Write a program to check if two strings are equal using relational operators.
33. Check if a number is even and greater than 100.
34. Write a program to check if a person is eligible for a senior citizen discount (age > 60 and has
a valid ID).
35. Explain the difference between and, or, and not with examples.
For Loops (Easy to Advanced)
36. Write a program to print numbers from 1 to 10 using a for loop.
37. Write a program to calculate the sum of all numbers in a list.
38. Use a for loop to print the multiplication table of a given number.
39. Write a program to iterate over a dictionary and print each key-value pair.
40. Write a Python program to find the factorial of a number using a for loop.
While Loops (Easy to Advanced)
41. Write a program to print numbers from 1 to 10 using a while loop.
42. Write a program to calculate the sum of the first n natural numbers using a while loop.
43. Write a program to check if a given number is a prime number using a while loop.
44. Implement a program to reverse a given number using a while loop.
45. Write a program to continuously accept user input until the user enters "quit".
Functions and Recursion (Intermediate to Advanced)
46. Write a Python function to find the square of a number.
47. Write a function that accepts a list of numbers and returns their average.
48. Implement a recursive function to calculate the factorial of a number.
49. Write a program to generate the Fibonacci series using recursion.
50. Write a Python function to check whether a given string is a palindrome or not.
If, Else, Elif, and Multiple If
1. Write a program to check if a number is odd or even.
2. Create a program that accepts a user's age and determines if they are a child (age < 13), a
teenager (13 ≤ age < 18), or an adult (age ≥ 18).
3. Write a program to classify grades:
o A if marks ≥ 90
o B if 80 ≤ marks < 90
o C if 70 ≤ marks < 80
o F if marks < 70
4. Check if a triangle is valid based on its three sides (sum of any two sides must be greater
than the third side).
5. Write a program to calculate the electricity bill based on usage:
o First 100 units: ₹5/unit
o Next 100 units: ₹7/unit
o Above 200 units: ₹10/unit.
Logical and Relational Operators
6. Write a program to check if a number is divisible by both 2 and 3.
7. Create a program to validate a password:
o It should be at least 8 characters long and contain a number.
8. Write a program to check if a given year is not a leap year.
9. Implement a program to check if a point (x, y) lies in the first quadrant.
10. Determine if a given string starts with a vowel and ends with a consonant.
For Loops
11. Print all prime numbers between 1 and 100.
12. Write a program to calculate the factorial of a number using a for loop.
13. Create a program that prints the following pattern for n = 5:
markdown
Copy code
**
***
****
*****
14. Write a program to find the sum of all odd numbers in a list.
15. Generate the Fibonacci sequence up to the nth term using a for loop.
16. Print the multiplication table for numbers 1 through 10.
17. Write a program to find all numbers between 1 and 500 that are divisible by 7 and end with
3.
While Loops
18. Create a program that keeps accepting numbers from the user and stops when the user
enters a negative number. Print the sum of all positive numbers entered.
19. Write a program to reverse the digits of a given number using a while loop.
20. Implement a countdown timer starting from 10.
21. Write a program to check if a number is a perfect number (sum of its divisors excluding itself
equals the number).
22. Simulate a login system with 3 attempts using a while loop.
23. Write a program to calculate the greatest common divisor (GCD) of two numbers using a
while loop.
Functions
24. Write a function to check if a number is prime.
25. Create a function to find the sum of squares of the first n natural numbers.
26. Write a function to find the maximum of three numbers.
27. Implement a function to count the number of vowels in a given string.
28. Create a function to calculate compound interest given principal, rate, and time.
29. Write a function to find the smallest and largest numbers in a list.
Recursion
30. Write a recursive function to calculate the power of a number (base raised to the exponent).
31. Implement a recursive function to reverse a string.
32. Create a recursive function to compute the sum of digits of a number.
33. Write a recursive function to solve the Tower of Hanoi problem for n disks.
34. Implement a recursive function to generate the nth Fibonacci number.
35. Write a program using recursion to check if a string is a palindrome.