How can I add two values replacing /
between them? I tried with item.replace("/","+")
but it only places the +
sign replacing /
and does nothing else. For example If i try the logic on 2/1.5
and -3/-4.5
, I get 2+1.5
and -3+-4.5
.
My intention here is to add the two values replacing
/
between them and divide it into 2 so that the result becomes1.875
and-3.75
respectively if I try the logic on (2/1.5
and-3/-4.5
).
This is my try so far:
for item in ['2/1.5','-3/-4.5']:
print(item.replace("/","+"))
What I'm having now:
2+1.5
-3+-4.5
Expected output (adding the two values replacing /
with +
and then divide result by two):
1.75
-3.75