Let's say I have a string named product
.
product
may be string such as "5*2"
or "12/3"
.
Does anyone know a way I can compute the output of a product or dividend such as this? Considering sum is a string.
Let's say I have a string named product
.
product
may be string such as "5*2"
or "12/3"
.
Does anyone know a way I can compute the output of a product or dividend such as this? Considering sum is a string.
check whether "/" or "*" are in your string and split it accordingly :)
product = "12/3"
if "*" in product:
first,sec = product.split("*")
print(float(first)*float(sec))
elif "/" in product:
first,sec = product.split("/")
print(float(first)/float(sec))