class Person:
"""Represents a person."""
class Human:
"""Represents a human."""
p = Person()
Given the above script
| How many classes are defined: | ||
| How many objects are created: | ||
| What class does the object p belong to: |
Create two classes, Book and Author.
Create an author, writer, with name and age attributes
Create a book, novel, with title: str, pages: int and author: Author attributes.
Create a class and any instance of it, save it to a variable, and assign any attribute to this instance.
class Horse:
pass
h = Horse()
h.name = "Storm"
h.age = 5
h.color = "Brown"
h.color = "Black"
h.age += 2
What is the value of the following expressions at the end of execution of the above script?
| h.color: | ||
| h.age: |
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 a class, Cup
Create a cup, c, with two attributes, color and volume.
Change c's color
Add 50 to c's volume
class Room:
pass
r = Room()
r.name = "Living Room"
r.lights_on = False
r.lights_on = True
What is the value of the following expressions at the end of execution of the above script?
| r.name: | ||
| r.lights_on: |
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
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 that represents city
Create an instance of it and assign it to c
Assign three attributes to it, name, population and is_capital, with values a string, an integer and a boolean respectively.