Python doesn't have anything like a do-while loop. So this is a technique you can do in any language called "loop and a half". It's pretty cool. I use them a lot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
You flip a coin and it is... HEADS
That's 1 in a row...
Would you like to flip again (y/n)? y
You flip a coin and it is... HEADS
That's 2 in a row...
Would you like to flip again (y/n)? n
Final score: 2
Basically you make an infinite loop on purpose. Then, at the bottom of the loop, you test whatever condition you want. If it's true, you break out of the loop.
- No study drills?!? Gasp!
©2017 Graham Mitchell