python practice questions
python practice questions
1. Write a function that takes a list of numbers and returns the sum of all elements using a for
loop.
2. Write a function that removes all duplicate elements from a list using a while loop.
3. Create a function that reverses a list without using built-in functions.
4. Write a function to find the maximum number in a list using a for loop.
5. Implement a function that checks if a given element exists in a list using a while loop.
6. Write a function that takes a tuple of numbers and returns a new tuple with only even
numbers.
7. Write a function that finds the index of a given element in a tuple using a for loop.
8. Create a function that converts a tuple of numbers into a list, modifies it, and returns the new
tuple.
9. Implement a function to merge two tuples using a for loop.
10. Write a function that calculates the sum of all elements in a tuple using a while loop.
11. Write a function that takes a set and a value, and removes the value if it exists using a while
loop.
12. Create a function that finds the union of two sets using a for loop.
13. Write a function to check if all elements of one set exist in another set using a loop.
14. Implement a function that finds the difference between two sets without using built-in
methods.
15. Write a function that converts a set to a list and returns the sorted list using a for loop.
16. Write a function that takes a dictionary and returns a list of all its keys using a loop.
17. Create a function that finds the key with the highest value in a dictionary.
18. Write a function that reverses keys and values in a dictionary using a for loop.
19. Implement a function that counts occurrences of each word in a list and stores them in a
dictionary.
20. Write a function that removes dictionary entries where values are less than a given threshold
using a while loop.