Python, search list of list and give next value
<p>I'm creating a program that given a percentage for commission and given an invoice(s), it will look for given invoices, look for the value of that invoice and calculate the commission based on the percentage input. When we input <code>"calculate"</code> it will sum all the commission and give me the total of commission. </p>

<p>I'm having trouble trying to identify the input within the list. Once I do that, what must I do to be given the value of that invoice?</p>

<p><code>data base = [Invoice, Invoice amount, invoice margin]</code></p>

<p>This is what I have so far. </p>

<pre><code>data_base = [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]]
comission_percentage = int(input("Comision Percentage: "))
invoice = input("Enter an invoice: ")
total_comision = 0


while invoice != "calculate" :
    while invoice in data_base:
        invoice_ = data_base.index(invoice)+1 #Gives me the position of invoice
        invoice_amount = data_base[p_factura] #Give me the value os the invoice
        comission = ((margen_comisionar/100)* monto_factura) #calculatecomission
        total_comision = comission + total_comission         
        invoice = input("Enter an invoice: ")
print("The amount to comission is: " + str(total_comission))
</code></pre>

<p>You would do better to split up the task of finding the right invoice from the calculations.</p>

<p>At present your code will not run at all, as you are using variables whose values you haven't defined. Since you don't need to alter the invoices at all it will be fine just to return the values you want. Here's an example, that returns an "empty" invoice in case it doesn't find the one you asked for:</p>

<pre><code>def find_invoice(s):
    for i_num, amount, rate in data_base:
        if i_num == s:
            return i_num, amount, rate
    return(None, 0.0, 0,0)
</code></pre>

<p>Then the main part of your logic can read:</p>

<pre><code>total_commission = 0.0
while invoice != "calculate":
    i, amt, rate = find_invoice(invoice)
    if i:
        total_commission += amt*comission_percentage/100.0
        invoice = input("Enter an invoice: ")
</code></pre>

<p>Also, be careful with variable names. Your spelling must be EXACT! Not a bad effort for an apparent beginner, though.</p>

python list element