Define a class, City, and define its __init__(self, name: str, population: int, country: str) method which sets city's name, population and country attributes.
Enable comparison between cities using >=.
Return True if the left city's population is greater than or equal to the right city's;
otherwise, return False.
Create two cities 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 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.
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 <.
class Dog:
"""Represents a dog.
attributes: name: str, weight: float (in kg)
"""
Write a Dog method, print_dog, that prints dog's information in the following format:
name - weightkgExample:
Bubi - 12.5kg
Create a dog, set its attributes and call print
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 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 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 Shape with __init__(self, name) method that sets the name attribute.
class Car:
"""Represents a car.
attributes: brand: str, mileage: int (in km)
"""
Write a Car method, display, that prints car's information in the following format:
brand - mileage kmExample:
Toyota - 55000 km
Create a car, set its attributes and call display