+ 2
i = 1 while i <=5: print(i) i = i + 1 print("Finished!")
This is my 3rd week learning python. I don't understand this code while I sort of can guess the output. if someone would kindly explain which line of code does what execution would be of great help. thank you https://www.sololearn.com/discuss/1248903/?ref=app
3 ответов
+ 5
i = 1 is a first value for i
then it check if i less than or equal to 5 it prints i and then add to it 1 and it will check again till i become more than 5 it will stop and go to the last line and print finished
so the result should be
1
2
3
4
5
Finished
+ 2
This is a more pythonic alternative to your question:
https://code.sololearn.com/cYPsHI7VsAwY/?ref=app
0
helpful, thank you