Create a program that prompts for a positive number greater than 2 (check this condition) and
then keeps taking the square root of this number until the square root is less than 2. Print the value
each time the square root is taken, along with the number of times the operation has been
completed. For example:
Enter an integer greater than 2: 20
1: 4.472
2: 2.115
3: 1.454
Answers
Answered by
1
import math
def sqrt(n):
sqrt = n
counter = 0
while sqrt > 2:
sqrt = math.sqrt(sqrt)
counter += 1
print(f"{counter}: {sqrt}")
while True:
n = int(input("enter a num > 2: "))
if n <= 2:
print("enter a number > 2!")
continue
else:
sqrt(n)
break
Answered by
0
Answer:
import math
def sqrt(n):
sqrt = n
counter = 0
while sqrt > 2:
sqrt = math.sqrt(sqrt)
counter += 1
print(f"{counter}: {sqrt}")
while True:
n = int(input("enter a num > 2: "))
if n <= 2:
print("enter a number > 2!")
continue
else:
sqrt(n)
break
Similar questions