0
the user enters a code and the desired quantity, this code refers to some value of the list and then the value of the list is multiplied by the quantity. of this multiplication I want the most expensive value (already got) and the cheapest, this last one I could not do because to make 'cheap = 0' would already make the smallest value possible, I enclosed here.
codigos = [4.20, 7.30, 8.50, 9.20, 10.30, 8.30]
val_tot = frete = caro = 0
barato = ?
while True:
menu = int(input('[1] Adicionar pedido \n[-1] finalizar programa: '))
if menu == -1:
break
elif menu == 1:
input('Digite o CPF: ')
cod = int(input('Digite o código do produto: '))
qtd = int(input(' Quatidade: '))
frete += 5
if cod == 100:
val_tot += codigos[0] * qtd
if codigos[0] * qtd > caro:
caro = codigos[0] * qtd
elif codigos[0] * qtd < barato:
barato = (codigos[0] * qtd)
elif cod == 101:
val_tot += codigos[1] * qtd
if codigos[1] * qtd > caro:
caro = codigos[1] * qtd
elif codigos[1] * qtd < barato:
barato = (codigos[1] * qtd)
elif cod == 102:
val_tot += codigos[2] * qtd
if codigos[2] * qtd > caro:
caro = codigos[2] * qtd
elif codigos[2] * qtd < barato:
barato = (codigos[2] * qtd)
elif cod == 103:
val_tot += codigos[3] * qtd
if codigos[3] * qtd > caro:
caro = codigos[3] * qtd
elif codigos[3] * qtd < barato:
barato = (codigos[3] * qtd)
elif cod == 104:
val_tot += codigos[4] * qtd
if codigos[4] * qtd > caro:
caro = codigos[4] * qtd
elif codigos[4] * qtd < barato:
barato = (codigos[4] * qtd)
elif cod == 105:
val_tot += codigos[5] * qtd
if codigos[5] * qtd > caro:
caro = codigos[5] * qtd
elif codigos[5] * qtd < barato:
barato = (codigos[5] * qtd)
print('Pedido mais caro: {}' .format(caro))
print('Pedido mais barato: {}' .format(barato))
print('Valor total arrecadado pelo motoboy: {}'.format(frete * 0.6))
print ('Valor arrecadado pela lanchonete: {}'.format(val_tot + (frete * 0.4)))
You can store in a variable the cheapest value and compare. If it is smaller you update this value.
– absentia
Start with
barato = 999999
?– Ronaldo Araújo Alves