-3
I need to find the most expensive item within a list.
The entry must contain the product code, quantity and price entered by the user in the same row in that order and each row is a product. Then the code needs to calculate the quantity * the value of all products that the user enters and check which is the most expensive item within the inserted items.
Output must be the product code, quantity and value only of the most expensive item among all the entered items.
I’ve tried absolutely everything I know and I can’t fix it because I can’t break the infinite loop.
Code
temp = []
listacustos = []
maior = 0
while True:
item = input().split()
temp.append(item)
if len(temp) == 0:
print ("nao tem compras")
else:
qtd = int(item[1])
valor = float(item[2])
custo = valor * qtd
item.append(custo)
listacustos.append(custo)
for c in range(len(listacustos)):
if listacustos[c] > maior:
maior = listacustos[c]
for p in temp:
if p[2] == maior:
print("Quantidade: {}".format(p[0]))
print("Codigo: {}".format(p[1]))
print("Custo: {}".format(p[3]))
If you want to know how to leave a loop, swap the title for something more descriptive. Ex: "How to abandon the while true loop: ?" and start the question by, "I made a program that calculates the highest value of a shopping list, the code is wrapped in a loop
while true:
would like to know how to wax this loop after the user has typed0 0 0
?"– Augusto Vasques