ABCDEFGHIJKLMNOPQRSTUVWXYZ
{'Name: ': 'Lincoln', 'Age: ': '15', 'Favorite_Game: ': 'COD'}
#Homework Part 1
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def print_people(people):
for person in people:
print(f"Name: {person.name}, Age: {person.age}")
person1 = Person("Ronit", 15)
person2 = Person("Lincoln", 15)
person3 = Person("Ishan", 15)
people_list = [person1, person2, person3]
print_people(people_list)
Name: Ronit, Age: 15
Name: Lincoln, Age: 15
Name: Ishan, Age: 15
The oldest person is Mom with an age of 48.
#Hack 2
import json
movie_theater = {}
movie1 = {
"title": "Revenge of the sith",
"rating": "9/10",
"best characters": ["Anakin Skywalker"+" "+"and Obi Wan"]
}
movie2 = {
"title": "Empire Strikes Back",
"rating": "9/10",
"best characters": ["Darth Vader"+" "+"and Luke Skywalker"]
}
movie_theater["movie1"] = movie1
movie_theater["movie2"] = movie2
with open('library.json', 'w') as file:
json.dump(movie_theater, file)
with open('library.json', 'r') as file:
loaded_library = json.load(file)
print("Loaded Library:")
for book_id, book_info in loaded_library.items():
print(f"Movie ID: {book_id}")
print(f"Title: {book_info['title']}")
print(f"Rating: {book_info['rating']}")
print(f"best characters: {', '.join(book_info['best characters'])}\n")
Loaded Library:
Movie ID: movie1
Title: Revenge of the sith
Rating: 9/10
best characters: Anakin Skywalker and Obi Wan
Movie ID: movie2
Title: Empire Strikes Back
Rating: 9/10
best characters: Darth Vader and Luke Skywalker