Square root of a specific number is defined as some other number which when multiplied with itself results in that specific number. For example – **Square root of b will be some number a such that b = a * a**. Do note that Square Roots only exists for positive numbers, complex numbers but not for negative numbers.

In this article, I’ll discuss How this logic around **Mathematical Square Root** can be implemented as **Python Code**.

There are multiple ways which can be used for doing this –

**Using sqrt function from Math Module****Using sqrt function form CMath Module**(Only For Complex Number)**Using Basic Mathematical Expression****Using pow() Python Function**

Let’s discuss each one of these **Code Designs for Finding Square Root of a Number in Python**.

Table of Contents

## Finding Square Root of a Number using sqrt function from Math Module

- Import sqrt function from Python’s Math Module
- Ask user for a number whose Square Root to be calculated
- If number entered by user is not positive, prompt user to enter positive number
- Otherwise pass user entered number to
**sqrt() function** **sqrt() function**will return**Square Root of Number**

### Python Code for Finding Square Root of Number

```
# Python Program for finding Square Root of Number
from math import sqrt # From Python's Math Module import sqrt function
# Define Number whose Square Root to be calculated
number = int(input("Enter a Number:"))
if(number >= 0):
sqrt_of_number = sqrt(number)
print("Square Root of Number",number,"is =>",sqrt_of_number)
else:
print("Please Enter a Positive Number")
```

**Output of Above Code**

```
Enter a Number:16
Square Root of Number 16 is => 4.0
```

## Finding Square Root of a Complex Number using CMath Module

- Import sqrt function from Python’s CMath Module
- Define a complex number like
**complex_number = 19 + 27j** - Pass complex number to
**sqrt function**which returns Square Root of Complex Number

### Python Code for Finding Square Root of Complex Number

```
# Python Program for finding Square Root of Number
from cmath import sqrt # From Python's Math Module import sqrt function
complex_number = 10 + 3j # A Complex Number in Python
sqrt_of_complex_number = sqrt(complex_number)
print("Square Root of Complex Number",complex_number,"is =>",sqrt_of_complex_number)
```

**Output of Above Code**

`Square Root of Complex Number (10+3j) is => (3.19689744196702+0.46920491733918884j)`

## Finding Square Root of a Number using Basic Mathematical Expression

- Just define a number like
**number = 10** - Multiply
**number**with 0.5, that’s it resulting value will be**square root of number**

### Python Code for Finding Square Root of Number

```
# Python Program for finding Square Root of Number
number = 10 # Define a Number
square_root_of_number = number ** 0.5
print("Square Root of", number, "is =>",square_root_of_number)
```

**Output of Above Code**

`Square Root of 10 is => 3.1622776601683795`

## Finding Square Root of Number using pow() Python Function

- Import pow function from Python’s Math Module
- Define a number like number = 12
- Pass defined number and 0.5 to
**pow() function**, which will return square root of defined number.

### Python Code for Finding Square Root of Number

```
# Python Program for finding Square Root of Number
# Import function pow from Python's Math Module
from math import pow
number = 12 # Define a number
square_root_of_number = pow(number, 0.5)
print("Square Root of", number, "is =>",square_root_of_number)
```

**Output of Above Code**

`Square Root of 12 is => 3.4641016151377544`

## No Comments

Leave a comment Cancel