Python Tests
Python Tests
2. Write a program that asks the user for their name and then prints a greeting message
including their name.
3. Write a program that calculates and prints the sum of two numbers entered by the user.
4. Write a program that takes a number as input and prints whether it is even or odd.
5. Write a program that calculates the area of a rectangle using the user-provided length and
width.
6. Write a program that prompts the user for a temperature in Celsius and converts it to
Fahrenheit.
7. Write a program that prints all the numbers from 1 to 100. For multiples of 3, print “Fizz”
instead of the number. For multiples of 5, print “Buzz”. For numbers that are multiples of both
3 and 5, print “FizzBuzz”.
8. Write a program that takes a list of numbers and returns the sum of all the elements in the
list.
10. Write a program that counts the number of occurrences of each character in a given string.
11. Write a program that takes a string as input and prints the reverse of that string.
12. Write a program that generates a random number between 1 and 10 and asks the user to
guess the number. Provide feedback if their guess is too high or too low, and let them keep
guessing until they guess the correct number.
13. Write a program that checks whether a given string is a palindrome (reads the same forwards
and backwards).
14. Write a program that calculates the factorial of a number entered by the user.
15. Write a program that takes a list of words as input and returns the longest word in the list.
16. Write a program that finds and prints all the prime numbers between 1 and 100.
17. Write a program that takes a sentence as input and counts the number of words in the
sentence.
18. Write a program that reads a CSV file containing student names and their scores, and prints
the average score.
19. Write a program that checks whether two strings are anagrams (contain the same characters
in a different order).
20. Write a program that reads a text file and counts the number of occurrences of each word in
the file.
21. Write a program that takes a list of numbers and removes all the duplicates, returning a new
list with unique elements only.
22. Write a program that prompts the user to enter a sentence and then prints the sentence in
uppercase letters.
23. Write a program that calculates the sum of the digits of a given number.
24. Write a program that takes a list of strings and sorts them in alphabetical order.
25. Write a program that checks whether a given string is a pangram (contains all the letters of
the alphabet).
26. Write a program that generates a random password of a given length. The password should
contain a mix of uppercase letters, lowercase letters, and digits.
27. Write a program that takes a list of numbers and returns the largest and smallest numbers in
the list.
28. Write a program that counts the number of vowels and consonants in a given string.
29. Write a program that reads a text file and replaces all occurrences of a specified word with
another word.
30. Write a program that takes a list of integers and removes all the negative numbers, returning
a new list with positive numbers only.
Remember, practicing is key to improving your programming skills. Take your time to work on these
questions, and don’t hesitate to refer to Python documentation or ask for help if you get stuck. Enjoy
your programming journey!