Answer to Question #244699 in Python for Isabel Cortez

Question #244699

8. Square Root

by CodeChum Admin


You've learned in the past lessons on how to use square root functions, right? Then let's take your knowledge to the test. Print out the square root of a given integer with only two decimal places.


Ready, solve, and go!


Input


A line containing an integer.


4


Output


A line containing a decimal with two decimal places.


2.00


1
Expert's answer
2021-10-03T06:35:39-0400
import math
integer_number = int(input("Enter an integer: "))
#Check whether the number is less than 0
if integer_number < 0:
    print("can't calculate the square root of a negative number")
else:
    #find the square root using the square root function in cmath
    square_root = math.sqrt(integer_number)
    #format to 2dps
    square_root = format(square_root, '.2f')
    #print the square root
    print("The square root of "+str(integer_number)+" is "+str(square_root))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS