Shorter Double Dice

Redo the Dice Doubles assignment (the dice program with a loop) so that it uses a post-test “while-true-break” loop instead of a regular while loop. Other than that it should behave exactly the same.

If you do this correctly, there should be less code in this version.

Name your file: shorter_double_dice.py

HERE COME THE DICE!

Roll #1: 3
Roll #2: 5
The total is 8!

Roll #1: 6
Roll #2: 1
The total is 7!

Roll #1: 2
Roll #2: 5
The total is 7!

Roll #1: 1
Roll #2: 1
The total is 2!

Frequently-Asked Questions

  • Why should we use a post-test “while-true-then-break” loop when a regular while loop will do?

    • It just cleans up the code a bit by reducing repeated code (which is a pattern you want to reduce whenever possible). See the DRY principal article


©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing