Create a class, any instance of it, save them to variables, and assign any attribute to this instance.
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.
Create a class named Car
Create an instance of Car and assign it to car1
Assign two attributes to car1, brand and year, with values "BMW" and 2020 respectively.
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: |
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: |
class Company:
"""Represents a company."""
What is the name of the defined class in the script above?
Create a class, Building
Create a building, b, with attribute floors, name, and elevators.
Add one more elevator to b.
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."""
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 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.