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 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 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.
Define a class, Student, and define its __init__(self, name: str, grade: int) method which sets dog's name and grade attributes.
Make it possible to compare if two students have the same grade using ==. Return True if students have the same grade, False otherwise.
Create two students and compare them using ==.
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 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 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
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, 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