I am trying to get some math out of a string, with no decimals it all worked perfectly, but when I started adding them in it stopped working, it doesn’t seem to leave the dot in there. I think my regex is right but can someone correct me?
result = re.findall('\d+\.?\d*\*\d+\.?\d*', e)
for x in result:
lst = x.split("*")
print lst
e = e.replace(x, str(float(lst[0])*float(lst[1])))
so if I put in "1.0*1.0" it should come out with 1.0 but it comes out with 100.0, this is because of the regex.
print lst comes out with [“10”, “10”] and not [“1.0”, “1.0”] so we can say that its not the line after that. Any ideas?
My understanding is that + means one or more ? means 0 or 1 and * means 0 or more
The input string was only coming in as 10*10 so I obviously did something wrong, in another module I had this code here that was done before I added decimals in…
this meant that
.would be deleted, so I needed to add this back in. So now I’m using this code:If anyone else could think of any mathematical symbols that should be in there it would help in the future. Thanks.