###############################
##8. Write an if statement that uses the turtle graphics library to determine
##whether the turtle’s heading is in the range of 40 degrees to 50 degrees
##including 40 and 50 in the range). If so, raise the turtle’s pen.
##Solution:
##angle = float(input('Enter the angle from 40 to 50: '))
##import turtle
##turtle.left(angle)
##turtle.forward(distance)
##if turtle.heading() >= 40 and turtle.heading() <= 50:
## turtle.penup()
## print('Turtle pen is up')
###8.1 A little extension of 8: Write an if statement that uses the turtle graphics
##library to determine whether the turtle’s nose (turtle coordinates) is closer
##to the point (100,100) than 5.
##If so, raise the turtle’s pen and print 'Good shot', if it is not so, don't
##raise anything just print 'Bad shot'.
##Solution possible:
## angle = float(input('Enter the angle between 40 and 50: '))
##distance = float(input('Enter the distance to go: '))
##import turtle
##turtle.left(angle)
##turtle.forward(distance)
##a = turtle.xcor()
##b = turtle.ycor()
##import math
##d = math.sqrt((a - 100)**2 + (b - 100)**2)
##if d < 5:
## turtle.penup()
## print('Good shot')
##else:
## print('Bad shot')
#### QUESTION: write this program without using math module and square root.
## Write your code here:
###########################
QUESTION: write this program without using math module and square root.
main.py
def square_root(num):
first = 0
last = num
x = 0
minimum_ranges = 0.0000000001;
while last - first > minimum_ranges:
x = (first + last) / 2.0;
powers = x * x
if abs(powers - num) <= minimum_ranges:
return x
elif powers < num:
first = x
else:
last = x
return x
number = int(input("Enter the number to root: "))
print(square_root(number))
Indentation:
Output:
Get Answers For Free
Most questions answered within 1 hours.