{"id":25362,"date":"2021-11-10T09:38:19","date_gmt":"2021-11-10T04:08:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=25362"},"modified":"2021-11-10T09:38:19","modified_gmt":"2021-11-10T04:08:19","slug":"python-sqrt-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-sqrt-method-with-examples\/","title":{"rendered":"Python sqrt() Method with Examples"},"content":{"rendered":"
sqrt() Method in Python:<\/strong><\/p>\n The square root of a number is returned by the math.sqrt() method.<\/p>\n Note:<\/strong> It should be noted that the number must be greater than or equal to 0.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n number:<\/strong> This is Required. A number whose square root is to be found.<\/p>\n Return Value:<\/strong><\/p>\n Returns a float value that represents a number’s square root.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Output:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n sqrt() Method in Python: The square root of a number is returned by the math.sqrt() method. Note: It should be noted that the number must be greater than or equal to 0. Syntax: math.sqrt(number) Parameters number: This is Required. A number whose square root is to be found. If the number is less than zero, …<\/p>\nmath.sqrt(number)<\/pre>\n
\n
Given Number = 36<\/pre>\n
The square root of a given number{ 36 } = 6.0<\/pre>\n
Given Number = 225<\/pre>\n
The square root of a given number{ 225 } = 15.0<\/pre>\n
sqrt() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as static input and store it in a variable.\r\ngvn_numb = 36\r\n# Pass the given number as an argument to the math.sqrt() function to get the\r\n# square root value of a given number.\r\n# Store it in another variable.\r\nsqure_rootrslt = math.sqrt(gvn_numb)\r\n# Print the square root value of a given number.\r\nprint(\"The square root of a given number{\", gvn_numb, \"} = \", squre_rootrslt)\r\n<\/pre>\n
The square root of a given number{ 36 } = 6.0<\/pre>\n
Similarly Check out for other numbers<\/h5>\n
import math\r\ngvn_numb = -25\r\nsqure_rootrslt = math.sqrt(gvn_numb)\r\nprint(\"The square root of a given number{\", gvn_numb, \"} = \", squre_rootrslt)\r\n<\/pre>\n
Traceback (most recent call last):\r\n File \"\/home\/47ab19f64e175f148c2a3f48359df760.py\", line 3, in <module>\r\n squre_rootrslt = math.sqrt(gvn_numb)\r\nValueError: math domain error<\/pre>\n
import math\r\ngvn_numb = 45.5\r\nsqure_rootrslt = math.sqrt(gvn_numb)\r\nprint(\"The square root of a given number{\", gvn_numb, \"} = \", squre_rootrslt)\r\n<\/pre>\n
The square root of a given number{ 45.5 } = 6.745368781616021<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the number as user input using the int(input()) function\r\n# and store it in a variable.\r\ngvn_numb = int(input(\"Enter some random number = \"))\r\n# Pass the given number as an argument to the math.sqrt() function to get the\r\n# square root value of a given number.\r\n# Store it in another variable.\r\nsqure_rootrslt = math.sqrt(gvn_numb)\r\n# Print the square root value of a given number.\r\nprint(\"The square root of a given number{\", gvn_numb, \"} = \", squre_rootrslt)\r\n<\/pre>\n
Enter some random number = 225\r\nThe square root of a given number{ 225 } = 15.0<\/pre>\n","protected":false},"excerpt":{"rendered":"