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 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 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 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.
class Student: """Represents a student. attributes: name: str, grade: int, school: str """ def print_detail(self): print(f'Name: {self.name}, School: {self.school}')
Write a method, set_values, that takes a string, name, an integer, grade, and a string, school. The method should assign those arguments to the respective attributes name, grade, and school.
Create a student and call set_values.
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
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 Movie: """Represents a movie. attributes: title: str, year: int, genre: str """ def display(self): print(f'Title: {self.title}, Year: {self.year}, Genre: {self.genre}')
Write a method, set_movie(title: str, year: int, genre: str), which sets objects title, year, and genre attributes.
Create a movie and set its attributes.
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 Tree: """Represents a tree. attributes: height: float, age: int """ def print(self): print(f"{self.height} - {self.age}") t = Tree() t.height, t.age = 30.0, 45 t.print()
What is printed after the execution of the above program?