0
For loop
Print a loop: 0 1 4 9 16 I've got: for i in range (0,5): i += (1) if i % 2 !=0: print(i) Any ideas how to increase each loop by an iteration of an odd number? x + 1, then x + 3, then x + 5, etc? Thanks for any help:)).
8 Answers
+ 4
Diego got it đ
+ 1
you could do what i did on this code
https://code.sololearn.com/co3k6QKJHU83/?ref=app
+ 1
for i in range(x):
print(i**2)
+ 1
Thanks, Aki:).
That does increase each integer by 1. Now, how do I increase each iterarion by an incramentally higher odd number (first + 1, then x + 3, then x+5, etc.)?
I'll edit my post now to reflect the actual desired outcome. :).
+ 1
Thanks David and Diego! i've tested it out and it works.
One more question:
It says: print(i**2)
Output: none
As (i**2) is any number times itself why isnt 0 â˘â˘ 2 achknowledged in this code?
Thanks for help!
+ 1
Perhaps you included the print statement in an if condition that is never met.The full code would look like this
for i in range(5):
print(i**2)
0
if so, then maybe this code can help
https://code.sololearn.com/c4On2dbkxWd6/?ref=app
0
Thanks, Aki! That's got the correct iteration. Now; how do we get it to start from zero?
x = int(input())
y = 1
for i in range(0,18):
print(x)
x+=y
y+=2