+ 2

What is Sqrt() in Python

I'm an intermediate in Python. And I was doing python for finance and I came across this thing called sqrt() and Idk what that is can I have help? https://www.sololearn.com/learning/1139/5194/13662/1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Link

20th Jan 2023, 11:54 AM
Solo-Rusty
Solo-Rusty - avatar
18 Respuestas
+ 15
sqrt() is a a python function used in a module called "math". This function is used to calculate the square root of the number. Examples: print(sqrt(36)) print(sqrt(49)) print(sqrt(81)) Output: 6.0 7.0 9.0
20th Jan 2023, 12:03 PM
Lamron
Lamron - avatar
+ 7
Hey Lamron as you state it's a function of module math. So first import math and call the function from it. Import math print(math.sqrt(x))
20th Jan 2023, 1:21 PM
JuZip
+ 5
Julian Zimpel exactly that, but for **import** command make sure everything is in lowercase
20th Jan 2023, 1:23 PM
Lamron
Lamron - avatar
+ 5
Julian Zimpel you can import some functions from modules, but I would recommend importing the whole module. **as** keyword allows you to refer to that module with a different name. Let's say we have a module called **ComputerScienceModule** It's too long to type each time, therefore you can use **as** keyword to give it a different name in your program. Example: import ComputerScienceModule as csm print(csm.function(value))
20th Jan 2023, 1:33 PM
Lamron
Lamron - avatar
+ 3
Square root. You can get the same result by calulating number x number (Or num * num) to get the result. You can do the opposite by dividing the num by num. Ex: 64 // num || or (float) 64/8
22nd Jan 2023, 6:26 AM
Andre Richmond
Andre Richmond - avatar
+ 2
Gemuh Hans Ujjwal Gautam Mr Williams , guys, great examples, but don't forget: square root operation is integer to float division. i.e. 36/6 = 6.0 It's not a floor division, i.e. 36//6 = 6 Therefore, if we do something like: print(math.sqrt(36)) We will get 6.0 Because we do: 36/6 Not: 36//6 See example: https://code.sololearn.com/cn5xPOtDRqNU/?ref=app
21st Jan 2023, 3:23 PM
Lamron
Lamron - avatar
+ 2
Thanks For answering my questions :)
23rd Jan 2023, 11:41 AM
Solo-Rusty
Solo-Rusty - avatar
+ 1
😅 indeed
20th Jan 2023, 1:24 PM
JuZip
+ 1
Lamron your code is fine with: from math import sqrt as sqrt print(sqrt(x))
20th Jan 2023, 1:29 PM
JuZip
+ 1
Lamron thats right, thanks for the reminder.
21st Jan 2023, 3:25 PM
Mr Williams
Mr Williams - avatar
0
I need help
20th Jan 2023, 12:01 PM
Solo-Rusty
Solo-Rusty - avatar
0
sqrt() is a function in the math module. It's becomes available when you import it at the start of your code. Import math print(math.sqrt(9)) = 3 print (math.sqrt(16)) = 4 And so on
21st Jan 2023, 2:27 AM
Gemuh Hans
0
sqrt() is a python function in . Math module Sqrt (Square Root ) it will calculate the square root of a function print(sqrt(9)) O/P -- 3
21st Jan 2023, 10:38 AM
Ujjwal Gautam
Ujjwal Gautam - avatar
0
Square Root
21st Jan 2023, 2:45 PM
Yusuf Tukur Auwal
Yusuf Tukur Auwal - avatar
0
Its square root of a number. So example if you Import Math Print(math.sqrt(36)) You will get 6
21st Jan 2023, 3:17 PM
Mr Williams
Mr Williams - avatar
0
After importing, you could check the number of functions within via print(len(dir(math))); it has 61 functions. If you don't need all of those, importing them is just going to slow the program down unnecessarily. [This site](https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/module_math.asp) is excellent for exploring the depths of python and other languages.
22nd Jan 2023, 3:18 AM
Jonathan Brooks
Jonathan Brooks - avatar
0
Why doesn't this support markdown?
22nd Jan 2023, 3:19 AM
Jonathan Brooks
Jonathan Brooks - avatar
0
Try these both to see if you notice the difference: from math import sqrt #one function to parse before use print(sqrt(81)) #delete the above import math as iloveslowapps #61 functions to parse before use print(sqrt(81) #by the way, I'm also working through the python for finance
22nd Jan 2023, 3:29 AM
Jonathan Brooks
Jonathan Brooks - avatar