Python: Generate a random number


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. '''
  2. Dice Roller - Generate two pseudo-random numbers
  3. @author: chrisaiv
  4. '''
  5.  
  6. import random
  7.  
  8. die1 = random.randrange(6) + 1
  9. die2 = random.randrange(6) + 1
  10.  
  11. total = die1 + die2
  12.  
  13. print "You rolled a", die1, "and a", die2, "for a total of ", total

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.