Deadline: October 11, 2024
Activity Type: Coding
Goal: Understand and apply the dictionaries data structure for various data sets.
Overview:
In this activity, you will practice using dictionaries to store and manage multiple instances of objects like Product, Employee, Books, University, and Restaurant. You will create dictionaries for these objects and populate them with details (e.g., names, prices, job titles). This activity is designed to help you understand how to manage collections of data in a structured manner.
This is a follow-up to Activity : Data Structure Again
Check this:
Instructions:
-
Create the following Python classes:
-
Product: Store product details (e.g., product name, price).
-
Employee: Store employee details (e.g., name, job title).
-
Books: Store book details (e.g., title, author).
-
University: Store university details (e.g., name, location).
-
Restaurant: Store restaurant details (e.g., name, cuisine type).
-
-
Use dictionaries to store the details of each class:
-
Create dictionaries for each object (e.g., list of product names, list of prices, list of employee job titles, etc.).
-
Populate the lists with at least 5 entries per object.
-
-
Access and print the details from the lists.
Example Using Lists:
Below is an example of how you can structure your data using lists for students, similar to the data you provided in the image:
Example: Student Data Using Lists
Student.py:
# Student 1
student_object1 = {
"name": "Juan Carlos",
"section": "BSIT-4B",
"id": 1,
"email": "juan@gmail.com",
"age": 22
}
# Student 2
student_object2 = {
"name": "Jose Rizal",
"section": "BSIT-2A",
"id": 2,
"email": "jose@gmail.com",
"age": 21
}
# Student 3
student_object3 = {
"name": "Juan Luna",
"section": "BSIT-3A",
"id": 3,
"email": "juanl@gmail.com",
"age": 20
}
# Student 4
student_object4 = {
"name": "Andres Bonifacio",
"section": "BSIT-3A",
"id": 4,
"email": "andres@gmail.com",
"age": 20
}
# Student 5
student_object5 = {
"name": "Justin Bieber",
"section": "BSIT-2A",
"id": 5,
"email": "justin@gmail.com",
"age": 21
}
# Student 6
student_object6 = {
"name": "Michael Jordan",
"section": "BSIT-4A",
"id": 6,
"email": "michael@gmail.com",
"age": 19
}
# Student 7
student_object7 = {
"name": "Andrew Jordan",
"section": "BSIT-4A",
"id": 7,
"email": "andrew@gmail.com",
"age": 19
}
# Student 8
student_object8 = {
"name": "Jessa Boe",
"section": "BSIT-2B",
"id": 8,
"email": "jessa@gmail.com",
"age": 18
}
# Student 9
student_object9 = {
"name": "Ted Talk",
"section": "BSIT-3B",
"id": 9,
"email": "ted@gmail.com",
"age": 19
}
students = [student_object1, student_object2, student_object3, student_object4, student_object5,
student_object6, student_object7, student_object8, student_object9]
for student in students:
print(f"Name: {student.get('name')}, Section: {student.get('section')}, Email: {student.get('email')}")
Explanation:
-
Each student is represented as a dictionary in Python, where the keys are the attributes (
name
,section
,id
,email
,age
), and the values are the respective details. -
The
get()
method in Python is used to safely access the values of the dictionary. -
All the students are stored in a list (
students
), and the loop iterates over each student dictionary to print their details.
Tasks:
-
Define dictionaries for storing data related to the classes: Product, Employee, Books, University, and Restaurant.
-
Populate the dictionaries with data for each class, ensuring there are at least 5 entries.
-
Access and print the details of each object from the list.
Submission:
-
Document your results on Hashnode.com or Medium.com.
-
Include your code snippets and output for each class.
-
Explain what you learned about using lists to store and access data.
-
I need to see more than 5 commits. use a best git naming convention
-
Standard naming convention for commit messages (thirdygayares.com)
-
name your GitHub repository MasterPythonDictionaries