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))

10th Nov 2019, 1:47 AM
Jacob Ferrari-Shaikh
Jacob Ferrari-Shaikh - avatar
10 ответов
+ 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))
10th Nov 2019, 7:06 AM
David Ashton
David Ashton - avatar
+ 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)))
10th Nov 2019, 1:54 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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) 🙂
11th Nov 2019, 2:57 PM
David Ashton
David Ashton - avatar
+ 1
Nevermind that didn't work! I don't get an output
10th Nov 2019, 3:01 AM
Jacob Ferrari-Shaikh
Jacob Ferrari-Shaikh - avatar
+ 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.
10th Nov 2019, 3:04 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
What would I do if I wanted to square a and b though and then square root the result?
10th Nov 2019, 3:52 AM
Jacob Ferrari-Shaikh
Jacob Ferrari-Shaikh - avatar
+ 1
Sorry square a and b and then add them and then square root the result
10th Nov 2019, 4:37 AM
Jacob Ferrari-Shaikh
Jacob Ferrari-Shaikh - avatar
+ 1
def c(a, b): return (a**2+b**2) print(c(2, 4)**(1/2))
10th Nov 2019, 7:14 AM
Abdul S Ansari
Abdul S Ansari - avatar
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
11th Nov 2019, 6:51 AM
Njeri
Njeri - avatar
0
David Ashton awesome that's what I was looking for! Didn't know **.5 worked as a square root
11th Nov 2019, 12:49 PM
Jacob Ferrari-Shaikh
Jacob Ferrari-Shaikh - avatar