class Person:
def __init__(self, name, age):
self.name = name
self.age = age
person1 = Person("John", 13)
person2 = Person("Doe", 16)
person3 = Person("HON", 12)
lst = [person1, person2, person3]
def print_people(Personlst):
for i in range(len(Personlst)):
print(Personlst[i].name, end=": ")
print(Personlst[i].age)
print_people(lst)
my_dict = {
"one": person1,
"two": person2,
"three": person3
}
def print_oldest(pdict):
oldest = list(pdict.keys())[0]
oldest_age = pdict[oldest].age
for name in pdict.keys():
if pdict[name].age > oldest_age:
oldest = name
oldest_age = pdict[name].age
print(pdict[oldest].name)
print_oldest(my_dict)
import json
secretNumber = 15
print(secretNumber) # int
print(type(secretNumber))
food = "Pizza"
print(food) # string
print(type(food))
names = ["Nandan", "Arnav", "Torin", "Remy"]
print(names) # list
print(type(names))
IamCool = True
print(IamCool) # boolean
print(type(IamCool)
names_2 = {
"Nandan": "TeamMate1",
"Arnav": "TeamMate2",
"Torin": "TeamMate3",
"Remy": "TeamMate4"
}
print(names_2) # dictionary
print(type(names_2)
variables = {
"numbers": [1, 2, 3, 4, 5],
"names": ["John", "Robert", "Bob", "Doe", "Bill"],
"isDict": True,
}
def print_largest(data_dict):
max_number = data_dict["numbers"][0]
for i in range(1, len(data_dict["numbers"])):
if max_number < data_dict["numbers"][i]:
max_number = data_dict["numbers"][i]
print(f"Largest Number is {max_number}")
longest_name = data_dict["names"][0]
max_length = len(data_dict["names"][0])
for i in range(1, len(data_dict["names"])):
if max_length < len(data_dict["names"][i]):
max_length = len(data_dict["names"][i])
longest_name = data_dict["names"][i]
print(f"Longest Name is {longest_name}")
if data_dict["isDict"]:
print("This is a dictionary")
else:
print("This is not a dictionary")
print_largest(variables)
Data Abstraction • 3 min read
Description
College Board Big Idea 3, Idea 9, Developing Algorithms