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?
Define a base class Employee with __init__(self, name, employee_id) that sets name and employee_id attributes.
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 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
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
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 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?
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: 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