Define a class, Product, and define its __init__(self, name: str, price: int) method which sets course's name and price attributes.
Allow comparison of products using the != operator. Return True if the products do not cost the same; otherwise, return False.
Create two products and compare them using !=.
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 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.
Define a class, Member, with its __init__(self, name: str, available_hours: set) method, which sets members name and available_hours attributes.
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 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 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 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.
Define a class, Laptop, and define its __init__(self, brand: str, storage: int) method which sets course's brand and storage attributes.
Enable comparison of laptops using the <= operator. Return True if the left laptop has equal or smaller storage capacity than the right one; otherwise, return False.
Create two laptops 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