Python 5.7: Limit the number of lives: while loop

<<<<<<< HEAD:en/course/py/lesson/5-7-limit-loop-while.html ======= >>>>>>> main:en/course/py/lesson/5.7-limit-loop-while.html

We are now going to add an additional event to improve our code, if I run for example my code, and I look for the magic number, you see that there is no limited number of times so here to improve our program we will add the number ... of lives which means in reality, the number of times that the user will have to try to find the magic number for that I will put number of lives at this level constant number of lives equal to five for a start and I will declare a variable lives, lives that is equal to number of lives in this part we will use the while loop to limit the number of lives or the number of tries and in the next video I will show you how to do it with the for loop so here we'll add and lives greater than 0 and here we'll Disincrement lives minus equal as well as here, lives minus eagal here I'll do a print you lost I'm going to rerun my code and we'll see what happens, I make the effort to lose you see that it tells us you've lost and if I rerun, I make the effort to win the magic number is greater the magic number is greater you see that it puts Bravo, even when I win it puts bravo you've won and you've lost so I'm going to come here I'm going to make a condition if lives equals zero so if the number of lives equals zero we'll display this like this and at this level I'm going to I'm going to do a print to say the number of lives we have left you have percentage s lives I'm going to put a percentage lives I'm going to rerun my code you have five lives left I'm going to put two the magic number is bigger you have 4 lives left I'm going to put five the magic number is bigger and you have left, I'm going to make the effort to lose you have 2 lives left the magic number is bigger, you're scared so we'd like when user loses at this level we're going to display the magic number was: so I'm going to put the I'll put the magic number percentage s I'll put the magic number percentage here I'll raise so to test first I'll put the number of lives to 2 the magic number is bigger you lost the magic number was ten so at this level we'll put our 5. Well that was all for this video we'll see you soon for the next one concerning the number of lives ... but with the for loop.