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 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?
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 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 City:
"""Represents a city.
attributes: name: str, population: int, country: str
"""
Write a City method, print_city, that prints city's information in the following format:
Name: city's name, Country: city's country | population peopleExample:
Name: Tirane, Country: Albania | 600000 people
Create a city, set its attributes and call print_city
Define a base class Employee with __init__(self, name, employee_id) that sets name and employee_id attributes.
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 <.
Define a base class Shape with __init__(self, name) method that sets the name attribute.
class Phone:
"""Represents a phone.
attributes: model: str, price: float
"""
Write a Phone method, print_details, that prints phone's information in the following format:
model - $priceExample:
iPhone 13 - $999.99
Create a phone, set its attributes and call print_details
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 >.