I am trying to write this loop in Python but get confused. Basically I have a starting angle 90 that I want to use a range of -90 to 90, iterating 10 times. After the loop is done, I want to divide the angle by half and repeat the process of using -45 to 45, by 10 iterations, etc.
The end values must be included, so 90 is the last value for the first loop, then 45 is the last value for the second loops, etc.
How can I write this elegantly and efficiently in Python?
startAngle = 90
for i in range(5):
for x in range(10):
print values from -startAngle to startAngle (startAngle included)
startAngle = startAngle / 2
angles(90)returns[-90, -72, -54, -36, -18, 0, 18, 36, 54, 72, 90]angles(45)returns[-45, -36, -27, -18, -9, 0, 9, 18, 27, 36, 45]You can now iterate over the return value, it is a list.
There are ten steps in my
anglesmethod returning eleven values.If you want another number of steps:
angles(90, 5)returns[-90, -45, 0, 45, 90]