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 <.
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 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 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 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 Country:
"""Represents a country.
attributes: name: str, population: int
"""
def show(self):
print(f'Country: {self.name}, Population: {self.population}')
Write method, set_country to set name and population.
Create a country and call set_country.
class City:
def details(self):
print(f"Name: {self.name}, Population: {self.population}")
c = City()
c.name, c.population = "Tetove", 84770
c.details()
What is printed after the execution of the above program?
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
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 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