Popcorn Hacks

%%python

name = "Eshaan"
print(name)
Eshaan
%%python

name = "Eshaan"
age = 16
highschooler = True
print(name, age, highschooler)
Eshaan 16 True
%%python

age = 16
number = 43
lebron = 23

print (age, number, lebron)

age = number
number = lebron

print (age, number, lebron)
16 43 23
43 23 23
%%python

interests = ["basketball", "football", "soccer", "tennis", "golf"]

print(interests[0])
print(interests[1])
print(interests[2])
print(interests[3])
print(interests[4])
basketball
football
soccer
tennis
golf
%%python

import json
sports = ["basketball", "football", "soccer", "tennis", "golf"]
json_sports = json.dumps(sports)
print(json_sports)
["basketball", "football", "soccer", "tennis", "golf"]

Hacks

%%python

secretNumber = 15
print(secretNumber)
print(type(secretNumber))

food = "Pizza"
print(food)
print(type(food))

names = ["Nandan", "Arnav", "Torin", "Remy"]
print(names)
print(type(names))

IamCool = True
print(IamCool)
print(type(IamCool))

##Bonus Problem:

names_2 = {
    "Nandan": "TeamMate1",
    "Arnav": "TeamMate2",
    "Torin": "TeamMate3",
    "Remy": "TeamMate4",
}

print(names_2)
print(type(names_2))
15
<class 'int'>
Pizza
<class 'str'>
['Nandan', 'Arnav', 'Torin', 'Remy']
<class 'list'>
True
<class 'bool'>
{'Nandan': 'TeamMate1', 'Arnav': 'TeamMate2', 'Torin': 'TeamMate3', 'Remy': 'TeamMate4'}
<class 'dict'>
%%python

name = "eshaan"
age = 16
agestring = str(age)
classlist = ["english", "math", "history", "physics", "compsci"]

print("My name is " + name + " and I am " + agestring + " years old.")
My name is eshaan and I am 16 years old.

Homework

%%python

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def print_people(self):
        print(self.name + " is " + str(self.age) + " years old.")
        
def oldest_person(people):
    oldest = None
    for person in people:
        if oldest == None:
            oldest = person
        elif person.age > oldest.age:
            oldest = person
    print(oldest.name + " is the oldest person.")
        
p1 = Person("Eshaan", 16)
p2 = Person("Aaron", 14)
p3 = Person("Brandon", 15)
p4 = Person("Ninaad", 18)
people = {p1, p2, p3, p4}
p1.print_people()
p2.print_people()
p3.print_people()
p4.print_people()
oldest_person(people)
Eshaan is 16 years old.
Aaron is 14 years old.
Brandon is 15 years old.
Ninaad is 18 years old.
Ninaad is the oldest person.