on writing a while loop for rolling two dice

Hope Rouselle hrouselle at jevedi.com
Sat Aug 28 16:46:52 EDT 2021


ram at zedat.fu-berlin.de (Stefan Ram) writes:

> Hope Rouselle <hrouselle at jevedi.com> writes:
>>How would you write this?
>
> """Rolls two dice until both yield the same value.
> Returns the number of times the two dice were rolled
> and the final value yielded."""
> roll_count = 0
> while True:
>     outcome = roll_two_dice()
>     roll_count += 1
>     if outcome[ 0 ]== outcome[ 1 ]: break
> return roll_count, outcome[ 0 ]

You totally convinced me.  Thanks.


More information about the Python-list mailing list