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 classes Book, Cover, and Publisher.
Create a cover, cv with color attribute.
Create a publisher, pb, with name attribute.
Create a book, bk, with cover: Cover and publisher: Publisher attributes
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 Movie:
"""Represents a movie."""
movie = Movie()
movie.title, movie.year = "The Shawshank Redemption", 1994
Given the above script
| What is name of the defined class: | ||
| What variable is the only class instance assigned to: | ||
| How many attributes does the only class instance have: | ||
| What is the first defined attribute name: | ||
| What is the second defined attribute name: | ||
| What is value of title movie attribute: | ||
| What is value of year movie attribute: |
Create one class, Dog.
Create a dog, dad, with name: str attribute
Create a dog, puppy, with name: str and parent: Dog attributes
Create two classes, School and Student.
Create a school and add some students to its students: list attribute.
Add one more student to school.
class Owl:
"""Represents an owl."""
huti = Owl()
bufi = Owl()
Given the above script
| How many classes are defined: | ||
| How many objects are created: | ||
| What class does the object huti belong to: | ||
| What class does the object bufi belong to: |
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.
Create a class and any instance of it, save it to a variable, and assign any attribute to this instance.