How can I output only the last result of my loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I output only the last result of my loop

For example a loop outputing: 1 2 3 How will I output only the "3"

27th May 2020, 8:21 AM
Awojobi Godfrey
Awojobi Godfrey - avatar
7 Answers
27th May 2020, 8:45 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 2
Awojobi Godfrey Just print the "stop" part of the loop
27th May 2020, 8:25 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 2
Just answer how will you run a loop without any termination ?
27th May 2020, 8:34 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 1
How will I print the stop part
27th May 2020, 8:30 AM
Awojobi Godfrey
Awojobi Godfrey - avatar
+ 1
Pls am a beginner, I dont still get u, explain with codes
27th May 2020, 8:36 AM
Awojobi Godfrey
Awojobi Godfrey - avatar
+ 1
Thanks understood
27th May 2020, 8:48 AM
Awojobi Godfrey
Awojobi Godfrey - avatar
0
The way you do is by adding a condition after a loop Code: for i in range(1:4): if i == 3: print(i) The condition works if the value of i equals 3. Hope it helps Happy coding
27th May 2020, 10:49 AM
BENJAMIN LIMBU SUBBA
BENJAMIN LIMBU SUBBA - avatar