group 1: Data abstraction bolean: True or false statement
first_variable = "Hello world"
print(first_variable)
Hello world
age= 15
name = "Aditi"
fail= True
print(age, name, fail)
15 Aditi True
kid1 = "aditi"
kid2 = "aditi2"
kid3 = "cindy1"
kid4 = "Eshika4"
kid1=kid3
kid2=kid3
kid3=kid4
kid4=kid1
print(kid1,kid2,kid3,kid4)
kid_list = [kid1, kid2, kid3, kid4, "Aditi1", True, 45]
print(kid_list[0])
print(kid_list[2])
cindy1 cindy1 Eshika4 cindy1
cindy1
Eshika4
Homework
# this is the established class for your variables name and age
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
# The self is used to represent the instance of the class. With this keyword, you can access the attributes and methods of the class in python.
# It binds the attributes with the given arguments. The reason why we use self is that Python does not use the '@' syntax to refer to instance attributes
final = []
#this is your function which will input ONE name and ask for the respective age as well. It will then be stored into this variable as person. So person has both a name and an age in it.
# Person is appended or added to the list in the end
# The x variable is used to ask for continuation incase there are more people.
def person_list():
x = "Y"
while x == "Y":
name = input("Input ONE name: ")
age = input("Input RESPECTIVE age: ")
person = Person(name, age)
final.append(person)
x = input("Input 'Y' for more people or 'N' to stop: ").upper()
person_list()
#this code is used to print the name of only one person and their age next to it. Because person has 2 variables in it, the one index will have both age and name. Since we created the class name and age, we can use this to get the name and age for the one index.
for i in range (len(final)):
print(f"{final[i].name} is {final[i].age} years old.")
i = i+1
esh is 15 years old.
Arn is 13 years old.
aditi is 14 years old.
Cindy is 16 years old.
other spins to the assignment given:
people_list = []
ages_list = []
while True:
name = input("Input a name (or 'N' to stop): ")
if name == 'N':
break
people_list.append(name)
age = input("Input the age for that person: ")
ages_list.append(age)
for x in range(len(people_list)):
print(people_list[x] + " " + "is"+ " " + ages_list[x])
x= x+1
m is 8
n is 9
people= {
"bob":15,
"Sally":17,
"George": 13,
"Billy":16,
}
def oldest_person(people):
age_list=[]
for person in people:
age= people[person]
age_list.append(age)
oldest = max(age_list)
print(oldest)
oldest_person(people)
17