dom1310df

Dice Simulator Mk 2

Oct 20th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  dice.py
  5. #  
  6. #  Copyright 2015 Dominic Davis-Foster <http://linustechtips.com/main/user/226337-dom1310df/>
  7. #  
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #  
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #  
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. #  MA 02110-1301, USA.
  22. #  
  23. #  
  24.  
  25. import random
  26.  
  27. def main():
  28.     total = 0       # initialize the variable to hold the sum of the rolls
  29.    
  30.     diceSides = int(raw_input("How many sides does the dice have? "))
  31.  
  32.     numRolls = int(raw_input("How many times would you like to roll the dice? "))
  33.  
  34.     # Roll the dice the given number of times
  35.     currentRoll = 1
  36.     while currentRoll <= numRolls:
  37.         # Using the module 'random', pick one number from the dice at random
  38.         diceRoll = random.randint(1,diceSides)
  39.        
  40.         # Print the number of dots, using fizzlesticks' suggestion
  41.         print('*' * diceRoll + ' ' + str(diceRoll) + " dots.")  
  42.  
  43.         total = total + diceRoll            # Add the current dice roll to the total
  44.         currentRoll = currentRoll + 1
  45.        
  46.     # Print the total
  47.     print("Total value of all rolls: " + str(total))
  48.    
  49.     return 0
  50.  
  51. if __name__ == '__main__':
  52.     main()
Advertisement
Add Comment
Please, Sign In to add comment