Coding
GitHub Copilot
# Write a product dataclass with information about the price, picture, url and description
################### Example of generated code ###################
from dataclasses import dataclass
@dataclass
class Product:
price: float
picture: str
url: str
description: str
def __post_init__(self):
self.price = round(self.price, 2)
def __str__(self):
return f"Product(price={self.price}, picture={self.picture},
url={self.url}, description={self.description})"
# Write a function that given a list of products, returns the cheapest and the most expensive one
################### Example of generated code ###################
from typing import List
def get_cheapest_most_expensive(products: List[Product]) -> (Product, Product):
if len(products) == 0:
return None, None
elif len(products) == 1:
return products[0], products[0]
else:
cheapest = products[0]
most_expensive = products[0]
for product in products[1:]:
if product.price < cheapest.price:
cheapest = product
if product.price > most_expensive.price:
most_expensive = product
return cheapest, most_expensiveGhostwriter
Ask Command

Last updated
