0
Can i square root the result of a function?
import math def c(a, b): return(a**2+b**2) print (math.sqrt(c))
10 Respuestas
+ 3
You could make it part of the function, e.g.
def sqrt_of_sum_of_squares(a, b):
return (a*a + b*b)**.5
print(sqrt_of_sum_of_squares(3, 4))
+ 2
c is the function itself, here is how you should do it:
a = int(input())
b = int(input())
print(math.sqrt(c(a, b)))
+ 2
Jacob Ferrari-Shaikh Thanks! You can also use the pow() function to get a square root, i.e. return pow(a*a + b*b, .5) 🙂
+ 1
Nevermind that didn't work! I don't get an output
+ 1
Jacob Ferrari-Shaikh show me your whole code, it should be working. Also, try it without input, directly give a and b values, for example:
print(math.sqrt(c(2, 5)))
Sololearn input is not very good, maybe that's where the problem is.
+ 1
What would I do if I wanted to square a and b though and then square root the result?
+ 1
Sorry square a and b and then add them and then square root the result
+ 1
def c(a, b):
return (a**2+b**2)
print(c(2, 4)**(1/2))
0
If you want the function c to give the square root of the sum of the squares directly, you could introduce an intermediate variable in the code and set it up like this:
https://code.sololearn.com/cVTbRYOtILzd/?ref=app
0
David Ashton awesome that's what I was looking for! Didn't know **.5 worked as a square root