flip.py


Below is the syntax highlighted version of flip.py from §1.3 Conditionals and Loops.


#-----------------------------------------------------------------------
# flip.py
#-----------------------------------------------------------------------

import stdio
import random

# Simulate a coin flip by writing 'Heads' or 'Tails' to standard
# output.

if random.randrange(0, 2) == 0:
    stdio.writeln('Heads')
else:
    stdio.writeln('Tails')
    
#-----------------------------------------------------------------------

# python flip.py
# Heads

# python flip.py
# Tails

# python flip.py
# Heads

# python flip.py
# Heads

# python flip.py
# Heads


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