class Car:
"""Represents a car.
attributes: brand: str, mileage: int (in km)
"""
Write a Car method, display, that prints car's information in the following format:
brand - mileage kmExample:
Toyota - 55000 km
Create a car, set its attributes and call display
class Player:
"""Represents a sports player.
attributes: name: str, sport: str
"""
def print_player(self):
print(f'Name: {self.name}, Sport: {self.sport}')
Write a method, set_player_attributes, to assign values to name and sport.
Create a player and assign values using set_player_attributes.
class Book:
"""Represents a book.
attributes: title: str, author: str, pages: int
"""
Write a Book method, print_book, that prints book's information in the following format:
Title: book title | Author: book author | Pages: number of pagesExample:
Title: Siddhartha | Author: Hermann Hesse | Pages: 160
Create a book, set its attributes and call print_book
class Cat:
"""Represents a cat.
attributes: name: str, age: int, color: str
"""
def print_info(self):
print(f'Name: {self.name}, Age: {self.age}, Color: {self.color}')
Write a method named set, which takes one string and two integers as arguments, name, age, and color. The method should set three attributes on the object: name, age, and color, and assign the corresponding arguments to them.
Create a cat and call the set method.
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.
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 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 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
Define a class, Book, and define its __init__(self, title: str, pages: int) method which sets dog's title and pages attributes.
Make it possible to compare which book has more pages using < operator. Return True if the left book has less pages than the right one, False otherwise.
Create two books and compare them using <.
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 >.