+ 2
How can I do this c programming code with for loop in py?
In c code, https://code.sololearn.com/cd21oewB5Zxl/#c In py code, https://code.sololearn.com/cO3NaVVZ9eYl/#py I can do the same code with python using while loop but I want to do this using for loop in python like I did in c code. How can I do that?
2 Answers
+ 3
This is one way. I have emulated your code by having the first number external of the loop.
The last line is just to copy your output style
res = [1]
for i in range(1,3):
res.append(i*2)
[print(i) for i in res]
+ 3
x = 1
for i in range(1, 5):
x = i*2
print(x)
if x >=5:
break