-1

I have this code below and my IF statement only ran once because missing_amount[i] never equals icl_dollar_amount[i]. How can I correct my script to say if missing amount is in icl_dollar_amount then run? All the missing_amounts ARE in icl_dollar_amount just they dont equal at the time of iteration, but they are inside my icl_dollar_amount list.

print missing amount and icl_dollar_amount:

Missing Amount :  2,760,127.58
ICL DOLLAR 325,845.84

Missing Amount :  325,845.84
ICL DOLLAR 13,389,914.67

Missing Amount :  6,887,299.6
ICL DOLLAR 6,887,299.60

code:

    body = browser.find_element_by_xpath("//*[contains(text(), 'Total:')]").text
        body_l.append(body)
        icl_dollar_amount = re.findall('(?:[\£\$\€]{1}[,\d]+.?\d*)', body)[0].split('$', 1)[1]
        icl_dollar_amount_l.append(icl_dollar_amount)
    if not missing_amount:
        logging.info("List is empty")
        print("List is empty")
    count = 0
    for i in range(len(missing_amount)):
        print(i)
        print("Missing Amount : ", missing_amount[i])
        print("ICL DOLLAR", icl_dollar_amount_l[i])
        if missing_amount[i] in icl_dollar_amount_l[i]:
            print("Inside the If Statement")
            body = body_l[i]
            get_company_id = body.split("Customer Id:", 1)[1][4:10].strip()
python2134
  • 21
  • 6
  • `in` checks whether a given element is in a list, which I presume is not what you want. What do you mean when you say "missing amount is in dollar amount"? – Silvio Mayolo Jan 12 '21 at 01:43
  • only Missing Amount : 6,887,299.6 ICL DOLLAR 6,887,299.60 worked because they were equal. But for example, 2,760,127.58 did not run because it didnt match 25,845.84 at the time of iteration. The thing is that 2,760,127.58 is in my list just does not match at time of iteration. – python2134 Jan 12 '21 at 01:46
  • I understand what the code is doing *now*. I don't understand what you *want* it to do. When do you want the if statement to run? I don't know what "this number is in this other number" means, from a logical perspective. – Silvio Mayolo Jan 12 '21 at 01:47
  • i meant the variable missing_amount is inside of icl_dollar_amount just its in different order so at time of iteration its not checking the icl_dollar_amount entire list.... – python2134 Jan 12 '21 at 01:48
  • If you want to check the whole list, then is it possible you simply want to say `missing_amount[i] in icl_dollar_amount_l`? Without the trailing `[i]`, I mean. – Silvio Mayolo Jan 12 '21 at 01:49
  • Read [Is floating point math broken?](https://stackoverflow.com/q/588004/5987) for why it's a bad idea to search for an exact decimal amount. – Mark Ransom Jan 12 '21 at 01:58

1 Answers1

0

I think this is happening because your code says "missing_amount[i] in icl_dollar_amount_l[i]". This is saying if the missing amount is in the icl dollar amount, not the icl dollar amount list. try changing to "if missing_amount[i] in icl_dollar_amount_l" and see if that gets you what you want.

Sriram A.
  • 78
  • 6