Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # dice.py
- #
- # Copyright 2015 Dominic Davis-Foster <http://linustechtips.com/main/user/226337-dom1310df/>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- #
- import random
- def main():
- total = 0 # initialize the variable to hold the sum of the rolls
- diceSides = int(raw_input("How many sides does the dice have? "))
- numRolls = int(raw_input("How many times would you like to roll the dice? "))
- # Roll the dice the given number of times
- currentRoll = 1
- while currentRoll <= numRolls:
- # Using the module 'random', pick one number from the dice at random
- diceRoll = random.randint(1,diceSides)
- # Print the number of dots, using fizzlesticks' suggestion
- print('*' * diceRoll + ' ' + str(diceRoll) + " dots.")
- total = total + diceRoll # Add the current dice roll to the total
- currentRoll = currentRoll + 1
- # Print the total
- print("Total value of all rolls: " + str(total))
- return 0
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment