-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 1 Question 5.py
More file actions
61 lines (50 loc) · 1.92 KB
/
Assignment 1 Question 5.py
File metadata and controls
61 lines (50 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#COMPLETED
#TESTED
"""
A person is standing and is looking at a pole in front of him.
Given the angle of view to the top (in degrees - should be between 0 and 90)
and the horizontal distance from the person to the base of the pole (in meters),
you have to find the height of the pole and the length of the line from the person to the top of the pole.
Your program has to take as input (from the user on the terminal) the angle (in degrees)
and another input for distance to the base of the pole.
Then it computes and prints the height of the pole and the distance to the tip of the pole.
Note. You must write functions to compute sin(), cos(), … using the series for them
and cannot use the python provided functions (e.g., in the math module).
If the value of pi is needed, you can use the standard value (3.14).
First, write these functions and test them.
Then write the main program to take inputs for angle and distance,
and call the functions to compute the height and distance.
"""
PI = 3.14
angle = int(input("Enter an angle between 0 and 90 degrees: "))
distance = float(input("Enter the horizontal distance from the person to the base of the pole (in meters): "))
angle = PI*angle/180
pole_height = 0
distance_to_tip = 0
def factorial(a):
fact = 1
while a>1:
fact = fact*a
a = a-1
return fact
def sin(a):
n = 1
sinx = 0
for i in range(10):
sinx = sinx + ((-1)**i)*((a**n)/factorial(n))
n = n+2
return sinx
def cos(a):
n = 0
cosx = 0
for i in range(10):
cosx = cosx + ((-1)**(i))*((a**n)/factorial(n))
n = n+2
return cosx
def tan(a):
tanx = sin(a)/cos(a)
return tanx
pole_height = distance*tan(angle)
distance_to_tip = distance/cos(angle)
print(f"The height of the pole is: {pole_height}")
print(f"The distance of the person from the tip of the pole is: {distance_to_tip}")