Define a class, Dog, and define its __init__(self, name, age) method which sets dog's name and age attributes.
Make it possible to compare which dog is older using the > operator. Return True if the left dog is older than the right one, False otherwise.
Create two dogs and compare them using >.
class Book:
"""Represents a book.
attributes: title: str, pages: int
"""
def print_book(self):
print(f'Title: {self.title}, Pages: {self.pages}')
Write a method, set(title: str, pages: int), that sets object's title and pages attributes.
Create a book and set its attributes.
class FootballPlayer:
"""Represents a football player.
attributes: name: str, goals: int
"""
Write a FootballPlayer method, print_detail, that prints player's information in the following format:
name - goals goalsExample:
Messi - 38 goals
Create a football player, set its attributes and call print_detail
class Dog:
"""Represents a dog.
attributes: name: str, weight: float (in kg)
"""
Write a Dog method, print_dog, that prints dog's information in the following format:
name - weightkgExample:
Bubi - 12.5kg
Create a dog, set its attributes and call print
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 >.
class Student:
"""Represents a student.
attributes: name: str, grade: int, school: str
"""
def print_detail(self):
print(f'Name: {self.name}, School: {self.school}')
Write a method, set_values, that takes a string, name, an integer, grade, and a string, school. The method should assign those arguments to the respective attributes name, grade, and school.
Create a student and call set_values.
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 Car:
"""Represents a car.
attributes: model: str, year: int
"""
def display(self):
print(f'Model: {self.model}, Year: {self.year}')
Write a method, assign, which takes a string and an integer, model and year. The method should assign these to the object's model and year attributes.
Create a car and call the assign method.
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 Student:
"""Represents a student.
attributes: first_name: str, last_name: str, grade: float
"""
Write a Student method, print_student, that prints student's information in the following format:
full name - gradeExample:
Sara Aliu - 8.6
Create a student, set its attributes and call print_student