Create two classes, School and Student.
Create a school and add some students to its students: list attribute.
Add one more student to school.
Create two classes, Backpack and Student.
Create a backpack, bp, with color attribute
Create a student, st, with name: str, grade: int and bag: Backpack attributes.
Create a class, Shoe
Create a shoe, s, with one attribute, size.
Add 1 to s's size
Create a class named Computer
Create an instance of Computer and assign it to pc
Assign two attributes to pc, brand and ram, with values "Lenovo" and 16 respectively.
class Bakery:
pass
class Cake:
pass
c1, c2 = Cake(), Cake()
c1.name, c2.name = "Chocolate", "Vanilla"
b = Bakery()
b.cakes = [c1, c2]
c = b.cakes.pop(-1)
print(c.name)
What is printed when we execute the above script
class House:
"""Represents a house.
attributes: owner, address
"""
class Owner:
"""Represents a house owner.
attributes: name
"""
class Address:
"""Represents an address.
attributes: street
"""
person = Owner()
person.name = "Blerina"
addr = Address()
addr.street = "Rr. Iliria"
h = House()
h.owner, h.address = person, addr
Given the above script:
| What is type of h.owner: | ||
| What is value of h.owner.name: |
Create two classes, Concert and Performer.
Create some performers with one attribute, name.
Create a concert and add created performers to its performers: list attribute.
Print names of all concert performers
class Person:
"""Represents a person.
attributes: name, best_friend
"""
p1 = Person()
p1.name = "Arta"
p2 = Person()
p2.name = "Zana"
p2.best_friend = p1
Given the above script:
| What is type of p2.best_friend: | ||
| What is value of p2.best_friend.name: |
Create two classes, Flight and Passenger.
Create three passengers and assign a name to each.
Create a flight and add some passengers to its passengers: list attribute.
Remove the last passenger from the flight
Print number of the flight passengers.
Create two classes, Library and Book.
Create a library, library and add some books to library.books dictionary
whose keys are characters and values are list of books whose title start with that character.
Example:
{'a': [<Book whose title is 'Ali baba'>, ...], 'o': [<Book whose title is 'Of Mice and Men'>, ...]}
Add a new book that starts with 's'.
Print the first book that starts with 's'.