Python Test
Python Test
2. Write a function that takes a list of numbers and returns a new list with each number
squared.
5. Write a Python program to handle a division by zero error using a try-except block.
6. Write a list comprehension to generate a list of even numbers between 1 and 20.
7. Create a simple Python class with an __init__ method that initializes a name attribute.
8. Write a Python program to read and print each line of a file called "data.txt".
9. Write a program that uses the len() function to print the length of a string and a list.
10. Write a Python program that doubles each number in a list using the map() function.
11. Write a Python program that sorts a list of dictionaries based on multiple keys. For
example, sort a list of students by "grade" first and then by "name" if the grades are the
same.
12. Write a program to compute the mean, median, and standard deviation of a NumPy
array.
13. Write a program to create a pandas Series and a DataFrame, each with at least two
elements.
14. Write a program to filter rows in a DataFrame where a specific column's value is greater
than 50.
15. Write a program to load a CSV file into a pandas DataFrame and display the first 5 rows.
16. Write a program to group data in a DataFrame by a column and calculate the average of
another column.
18.Write a function that takes a list of integers and returns a list of only the unique elements,
without using the set() function
19. Write a program to replace missing values in a DataFrame with the mean of their
column.
20. Write a program to create a NumPy array, find its shape, and print all elements greater
than a given value.