0
arithmetic progression and python
So basically i dont know how to write a code that calculates arithmetic progression that goes like (a1 = an * 2) i think the formula is like that but leme explain a1 = 1×2 = 2 a2 = 2x2 = 4. a3 = 3x2 = 6 a4 = 4x2 = 8 and i need to get to a64 so maybe there is a code that does it for me ?
3 odpowiedzi
0
This is very simple, if I understand your explanation correctly. All you have to do is take a number, and multiply it by two. For example, here's a function:
def arithmetic_progression(num):
return num * 2
print(arithmetic_progression(64))
Output: 128
If you want to run this function over and over again until 128, all you have to use a for loop:
for num in range(1, 129):
print(arithmetic_progression(num))
0
Aymane Boukrouh [INACTIVE] ...did a similar thing to what your trying to do...He did in his three lines of code code (see link) what would of taken me more than 52 lines....it'll give you an idea where to start... absolutly briliant.
https://code.sololearn.com/cBVhBfHv3o63/?ref=app#py
0
Thanks