Tutorialspoint
Problem
Solution
Submissions

Find the Square Root of a Number

Certification: Basic Level Accuracy: 82.8% Submissions: 186 Points: 5

Write a Python program that calculates the square root of a given number.

Example 1
  • Input: 16
  • Output: 4.0
  • Explanation:
    • Step 1: Calculate the square root of 16.
    • Step 2: √16 = 4.0.
    • Step 3: Return 4.0 as the result.
Example 2
  • Input: 7
  • Output: 2.6457513110645907
  • Explanation:
    • Step 1: Calculate the square root of 7.
    • Step 2: √7 = 2.6457513110645907.
    • Step 3: Return 2.6457513110645907 as the result.
Constraints
  • 0 ≤ number ≤ 10^9
  • Return the result with full precision
  • Time Complexity: O(1) or O(log n) if implementing manually
  • Space Complexity: O(1)
NumberPwCKPMG
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use math.sqrt() function: import math; result = math.sqrt(num)
  • Use the exponentiation operator: result = num ** 0.5
  • Implement Newton's method for manual calculation
  • Use binary search method for manual implementation

The following are the steps to find the Square Root of a Number:

 1. Define a function `square_root(n)` that takes a number.

 2. Compute the square root using `n ** 0.5`.
 3. Return the computed value.
 4. Call `square_root(25)` and store the result.
 5. Print the square root.

Submitted Code :