+ 1
Problem with geometric average
Hi, I'm trying to get the right output problem: I want to calculate the output of the geometric average of a*b. a and b should be positive and float. If a or b is negative, I have to print out "Error". When I check it with a or b as a negative value such as -1.0, I get a ValueError: MathDomainError. Can someone explain me why my code runs wrong, please ? https://code.sololearn.com/ceW3aeU9IF89/?ref=app
2 Réponses
+ 3
You can see one possible solution for this calculation. Hope it helps you.
https://code.sololearn.com/csTvp60QDK54/?ref=app
+ 2
No need to use the elif statement.
if a >= 0 and b >= 0:
print(math.sqrt(a*b))
else:
print("Error")