Python Assignment: Data Structures,
Functions, Numpy & Pandas
Instructions
• Attempt all questions.
• Submit the completed assignment in .ipynb format.
• Use appropriate function definitions and comments for clarity.
Assignment Questions
Section A: Data Structures & Control Structures
1. Create a list of 5 integers. Perform and print the result of the following operations:
append, extend, insert, remove, pop, clear, index, count, sort, and reverse.
2. Create a tuple that stores 3 student names. Try changing the second name in the tuple.
What happens? Explain why.
3. Create a set of integers with some duplicate values. Print the set and explain the output.
4. Create a dictionary with the keys: 'name', 'age', and 'city'. Update the age and add a new
key 'email'. Print the final dictionary.
5. Write a script that checks if a person is eligible to vote (age ≥ 18). Take age as a variable
and print the appropriate message.
6. Given a 'marks' variable, print the grade:
- 90 and above: 'A'
- 75–89: 'B'
- 50–74: 'C'
- Below 50: 'Fail'
7. Given a number, check if it's positive, and if it is also even. If not positive, print if it's
zero or negative.
Section B: Numpy
8. Create:
- A scalar using [Link](5)
- A 1D array with values 1 to 5
- A 2D array (2x3) with values from 10 to 60 in steps of 10
9. Generate a 4x4 Numpy array of random integers between 0 and 100 using
[Link]().
10. Create a 2D numpy array of shape (3x3). Convert it into a pandas DataFrame and add
column names: 'A', 'B', 'C'.
Section C: Exploring Pandas
11. Create a small DataFrame manually with 10 rows and columns: 'Name', 'Age', 'City', and
'Salary'. Then:
- Use .info(), .describe()
- Select 'Name' and 'City' columns
- Drop 'City' column
- Fill any missing values in 'Salary' column with the mean
- Remove any duplicate rows