+ 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

2nd May 2018, 9:44 AM
Raman Baniya
Raman Baniya - avatar
3 Answers
+ 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
2nd May 2018, 10:11 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 2
This is a more pythonic alternative to your question: https://code.sololearn.com/cYPsHI7VsAwY/?ref=app
2nd May 2018, 5:41 PM
Johannes
Johannes - avatar
0
helpful, thank you
2nd May 2018, 1:32 PM
Raman Baniya
Raman Baniya - avatar