Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Assignment_ Exploring Python Data Structures

The assignment focuses on exploring Python data structures including lists, tuples, dictionaries, and nested dictionaries. It consists of four parts where students are required to perform various operations such as adding, removing, and updating elements, as well as calculating averages and handling errors. Students must submit their Python code along with any observations regarding errors encountered during the process.

Uploaded by

Somebody's Bae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment_ Exploring Python Data Structures

The assignment focuses on exploring Python data structures including lists, tuples, dictionaries, and nested dictionaries. It consists of four parts where students are required to perform various operations such as adding, removing, and updating elements, as well as calculating averages and handling errors. Students must submit their Python code along with any observations regarding errors encountered during the process.

Uploaded by

Somebody's Bae
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment: Exploring Python Data Structures

Objective:
Understand how to work with lists, tuples, and dictionaries in Python. Complete the tasks below
and submit your work before the next class.

Part 1: Lists

1. Create a list named fruits with the following items: "apple", "banana", "cherry", "date".

2. Perform the following operations:


- Add "elderberry" to the end of the list.
- Remove "banana" from the list.
- Insert "blueberry" between "apple" and "cherry".
- Print the number of items in the list.
- Sort the list in alphabetical order.

Expected Code:

Part 2: Tuples

1. Create a tuple named dimensions with the following values: 10, 20, 30.

2. Write code to:


- Access and print the second value in the tuple.
- Attempt to change the first value (this should result in an error, explain why).
- Loop through the tuple and print each value.

Expected Code:
Part 3: Dictionaries

1. Create a dictionary named student_grades with the following key-value pairs:


- "Alice": 85
- "Bob": 90
- "Charlie": 78

2. Write code to:


- Add a new student "Diana" with a grade of 92.
- Update Charlie's grade to 80.
- Remove Alice from the dictionary.
- Print all students and their grades.

Expected Code:

Part 4 : Nested Dictionaries

1. Create a nested dictionary named class_grades where each key is a student's name and the
value is another dictionary that contains their grades for different subjects:

2. Write code to:


- Add a new student "Diana" with grades: Math = 88, Science = 91, English = 86.
- Update Bob’s Science grade to 90.
- Print the average grade of each student.
- Remove Charlie from the dictionary.
- Print all student names and their grades in all subjects.
Expected Code:

Additional Questions (Optional):


1. Challenge: Write code to find which student has the highest average grade and print their
name and average.
- Hint: Use a loop to keep track of the highest average while iterating through the dictionary.

Submission Guidelines:

- Submit the Python file containing your code.


- You can include comments to explain each part of the code.
- If you run into errors or unexpected behavior, write down your observations and thoughts on
what went wrong.

You might also like