I am writing an algorithm which should be able to determine in which quadrant a radian is based on two values that the user inputs. I think that the code is calculating the radian but I know that those values are not being compared to the pi values that I gave since I am not getting any output.
Code below:
JavaScript
x
21
21
1
print('Enter the radians of the angle (a*π/b): ')
2
a = int(input('a value(top): '))
3
b = int(input('b value(bottom): '))
4
5
radians = ((a*math.pi)/b)
6
7
print('')
8
print('Finding...')
9
10
if radians > 0 and radians < (math.pi/2):
11
print(f'The angle {radians}rad is in the I quadrant')
12
13
if radians > (math.pi/2) and degrees < math.pi:
14
print(f'The angle {radians}rad is in the II quadrant')
15
16
if radians > math.pi and radians < (3*math.pi/2):
17
print(f'The angle {radians}rad is in the III quadrant')
18
19
if radians > (3*math.pi/2) and radians < (2*math.pi):
20
print(f'The angle {radians}rad is in the IV quadrant')
21
Advertisement
Answer
First of all, you should rename degree to radians. The other problem is that you are assumed that all inputs are between 0 and 2pi. You should consider other inputs.
JavaScript
1
28
28
1
import math
2
3
print('Enter the radians of the angle (a*π/b): ')
4
a = int(input('a value(top): '))
5
b = int(input('b value(bottom): '))
6
7
radians = ((a*math.pi)/b)
8
9
print('')
10
print('Finding...')
11
12
while radians > 2 * math.pi:
13
radians -= 2 * math.pi
14
while radians < 0:
15
radians += 2 * math.pi
16
17
if 0 < radians < (math.pi / 2):
18
print(f'The angle {radians}rad is in the I quadrant')
19
20
if (math.pi / 2) < radians < math.pi:
21
print(f'The angle {radians}rad is in the II quadrant')
22
23
if math.pi < radians < (3 * math.pi / 2):
24
print(f'The angle {radians}rad is in the III quadrant')
25
26
if (3 * math.pi / 2) < radians < (2 * math.pi):
27
print(f'The angle {radians}rad is in the IV quadrant')
28