class Player:
def print_player(self):
print(self.name)
def set_player(self, name, goals):
self.name = name
self.goals = goals
p = Player()
p.set_player("Rod", 57)
p.print_player()
What is printed after the execution of the above program?
class Car:
"""Represents a car.
attributes: model: str, year: int
"""
def display(self):
print(f'Model: {self.model}, Year: {self.year}')
Write a method, assign, which takes a string and an integer, model and year. The method should assign these to the object's model and year attributes.
Create a car and call the assign method.
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 >=.
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 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 Laptop:
"""Represents a laptop.
attributes: brand: str, ram: int (in GB)
"""
Write a Laptop method, print_info, that prints laptop's information in the following format:
brand - RAMGBExample:
Dell - 16GB
Create a laptop, set its attributes and call print_info
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.
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, 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 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?