+ 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?

16th Nov 2020, 5:58 PM
The future is now thanks to science
The future is now thanks to science - avatar
2 Respostas
+ 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]
16th Nov 2020, 6:22 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
x = 1 for i in range(1, 5): x = i*2 print(x) if x >=5: break
16th Nov 2020, 6:48 PM
Shadoff
Shadoff - avatar