Define a base class Shape with __init__(self, name) method that sets the name attribute.
Define a class, Book, with its __init__(self, title, author, year, available) method, which sets title (str), author (str), year (int), and available (bool) attributes.
class Tree:
"""Represents a tree.
attributes: height: float, age: int
"""
def print(self):
print(f"{self.height} - {self.age}")
t = Tree()
t.height, t.age = 30.0, 45
t.print()
What is printed after the execution of the above program?
class Movie:
"""Represents a movie.
attributes: title: str, year: int
"""
Write a Movie method, print, that prints movie's information in the following format:
title (year)Example:
Inception (2010)
Create a movie, set its attributes and call print
class Bird:
def set_attributes(self, species, sound):
self.species = species
self.sound = sound
def sing(self):
print(self.sound)
owl = Bird()
owl.set_attributes("Owl", "hoot")
owl.sing()
What is printed after the execution of the above program?
class House:
"""Represents a house.
attributes: address: str, rooms: int, area: int
"""
def show_info(self):
print(f'Address: {self.address}, Area: {self.area} m square')
Write a House method. set_house_attrs, that sets all three attributes.
Create a house and call set_house_attrs.
class Laptop:
"""Represents a laptop.
attributes: brand: str, ram: int, storage: int
"""
def print_specs(self):
print(f'Brand: {self.brand}, RAM: {self.ram}GB, Storage: {self.storage}GB')
Write method, configure, to set brand, ram, and storage.
Create a laptop and call configure.
Define a class, Course, and define its __init__(self, title: str, duration_weeks: int) method which sets course's title and duration_weeks attributes.
Allow comparison of course durations using the > operator. Return True if the left course lasts longer than the right one; otherwise, return False.
Create two courses and compare them using >.
Define a class, Fighter, and define its __init__(self, name: str, strength: int) method which sets course's name and strength attributes.
Enable comparison of fighters using the < operator. Return True if the left fighter is less powerful than the right one; otherwise, return False.
Create two fighters and compare them using <.
class Cat:
"""Represents a cat.
attributes: name: str, age: int
"""
Write a Cat method, print_cat, that prints cat's information in the following format:
name - ageExample:
Nina - 3
Create a cat, set its attributes and call print_cat