L
L
liaset2020-05-25 15:17:06
Python
liaset, 2020-05-25 15:17:06

Who can solve a problem in python?

Victor wants to build a fence around his new house.
Bricks are needed to build a fence . To do this, he must choose the cheapest and best quality
bricks, because he does not want to spend a lot of money on this fence.
N companies applied to build the fence. Each company has a name - S, the price
of bricks X for a building 1 meter long and quality Y. Help Vita
determine the most profitable company, which has the cheapest and then the highest
quality
bricks.

Help me please! who is not difficult

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-05-25
@NeiroNx

from random import random
N = 100
#Создадим список компаний из 100 компаний цена от 2000 до 3000, качество от 150 до 200 единиц 
orders = [{"name":"Company {0:03d}".format(x),"price":2000+int(random()*1000),"quality":150+int(random()*50)} for x in range(N)]
#отсортируем по отноцению цена/качество наиболее выгодные будут в внчале списка
orders = sorted(orders,key=lambda x: x["price"]/x["quality"])
print("Top 5:"+",\t".join(orders[0].keys()))#заголовок
#выведем 5 первых по выгоде
print("\n".join([",\t".join(map(str,x.values())) for x in orders[:5]]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question