0

I don't know what is wrong with my code:

def check_Price():
   title = soup.find(id="productTitle").get_text()
   price = soup.find(id="priceblock_ourprice").get_text()
   converted_price=float(price[2:8])

  if(converted_price>42,999):
     send_mail()
  )

After running this code it is giving me following error:

converted_price=float(price[2:8])
ValueError: could not convert string to float: '42,999'
4
  • The problem is the ",". It can only handle ".". So what you need to to is to replace it Commented Jul 10, 2020 at 12:43
  • 2
    Float literals in python are like 42.999 you cannot use a comma seperator Commented Jul 10, 2020 at 12:44
  • Can you please mark it out I didn't Understand that quite well Commented Jul 10, 2020 at 12:46
  • Thank You So Much Now I understand What was wrong Commented Jul 10, 2020 at 12:48

1 Answer 1

1

For converting to float, the string can have only numbers and upto one '.' in the string. You could use the below one or make it more generic.

price[2:8].replace(',','')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.