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?
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 !=.
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
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 FootballPlayer:
"""Represents a football player.
attributes: name: str, goals: int
"""
Write a FootballPlayer method, print_detail, that prints player's information in the following format:
name - goals goalsExample:
Messi - 38 goals
Create a football player, set its attributes and call print_detail
Define a class, Book, and define its __init__(self, title: str, pages: int) method which sets dog's title and pages attributes.
Make it possible to compare which book has more pages using < operator. Return True if the left book has less pages than the right one, False otherwise.
Create two books and compare them using <.
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 Phone:
"""Represents a phone.
attributes: brand: str, price: float
"""
def print_info(self):
print(f'Brand: {self.brand}, Price: ${self.price}')
Write a method, setup, that takes two arguments, a string, brand, and an integer, price. The method should assign them to object's brand and price attributes.
Create a phone and call setup.
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?