# roll dice and keep rolling until you quit # # load the random class # import random # # assume user wants to roll the dice # print "After each roll, hit return to continue" print "or any key followed by return to stop " quit = None # # now roll repeatedly until done # while not quit: # it's a 20-sided die; note we add 1 because the random number # generated is between 0 and 19 (20-1) inclusive; by adding 1, # we will print a number between 1 and 20 die = random.randrange(20) + 1 print "You rolled a 20 sided die and", die, "came up.", # # see if she wants to go again # if raw_input("Again? ").strip() != "": quit = "Bye-bye!" print quit