'Error while calculating taxes: TypeError: can't multiply sequence by non-int of type 'float'
I try to calculate my taxes using python, but I get:
TypeError: can't multiply sequence by non-int of type 'float'
Code:
price_without_taxes = driver.find_element_by_xpath("//div[@id='__next']/div/main/div/div/div/p/span").text
print('LE PRIX EST DE :' + price_without_taxes)
tps = price_without_taxes * 0.05
tvq = price_without_taxes * 0.09975
price_with_taxes = float((price_without_taxes + tps + tvq))
print("Sous-Total: " + "%1.2f" % price_with_taxes + "$\n")
print("Livraison: " + str(10) + "$\n")
print("Total: " + "%1.2f" % price_with_taxes + "$\n")
Solution 1:[1]
Your variable, prices_without_taxes is a string rather than an int/float. You can not multiply text by floats. You would have to convert your string to an int/float first: float(prices_without_taxes) * (multiple)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Neuron |
