Loop Practice
Video Summary: https://youtu.be/KFHVBWSCbQw
Consider this solution to a prior exercise, which rolled two dice and declared a winner, if there was one, between the two:
Modify the program so that it uses a loop to keep playing.
- At the end of each roll, prompt the user asking if they would like to play again, and to enter 'y' if yes, 'n' if no
- Check if the user input 'y', 'n', or something else
- If 'y', roll again. If 'n', end the program. If something else, prompt the user again without rolling the dice
When you are finished, your output might look like this:
Player one rolled 3 Player two rolled 5 Player two wins! Would you like to roll again? Enter y for yes or n for no y Player one rolled 2 Player two rolled 3 Player two wins! Would you like to roll again? Enter y for yes or n for no a You must enter y for yes or n for no n The game has ended