sumoftwodice.py


Below is the syntax highlighted version of sumoftwodice.py from §1.2 Built-in Types of Data.


#-----------------------------------------------------------------------
# sumoftwodice.py
#-----------------------------------------------------------------------

import stdio
import random

# Roll two six-sided dice, and write the resulting sum to standard
# output.

SIDES = 6

a = random.randrange(1, SIDES+1)
b = random.randrange(1, SIDES+1)

total = a + b

stdio.writeln(total)

#-----------------------------------------------------------------------

# python sumoftwodice.py
# 5

# python sumoftwodice.py
# 7

# python sumoftwodice.py
# 10

# python sumoftwodice.py
# 7


Copyright © 2000–2015, Robert Sedgewick, Kevin Wayne, and Robert Dondero.
Last updated: Fri Oct 20 20:45:16 EDT 2017.