Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from random import *
  4.  
  5. def make_stat():
  6.     """
  7.    This function rolls three six-sided dice (3d6) and returns the result. It really
  8.    has no other function than that.
  9.    """
  10.     dice1 = randint(1,6)
  11.     dice2 = randint(1,6)
  12.     dice3 = randint(1,6)
  13.     total_dice = dice1 + dice2 + dice3
  14.     return total_dice
  15.  
  16. """
  17. unlimited_dice function:
  18. The purpose of the limited dice function is:
  19. The function rolls xd6 dice.
  20. Each die is added to a list
  21. Afterwards, the function checks the list for the result 6. If there is a 6 in
  22. the list, the function will replace that 6 with two new dice. It repeats this
  23. untill there is no 6 in the list, in which case it will add the results together
  24. and return that value.
  25.  
  26. An example:
  27. The user specifies 3d6 is to be rolled.
  28. The function runs random.randint(1,6) three times. The rolls turns out to be
  29. 1, 4 and 6, which is added to die_rolls, which is no [1, 4, 6]. When the
  30. checks the list if find the 6. It takes away the 6, and rolls random.randint(1,6)
  31. two more times. This time they are 6 and 6. Again, it replaces each 6 with two
  32. other rolls, in this case the rolls are 1, 1, 4, 6. This list is now:
  33. [1, 4, 6, 1, 1, 4, 6]. It replaces the 6 with two new rolls, 2 and 3. The list
  34. is [1, 4, 6, 1, 1, 4, 2, 3]. Now there are no 6, and so the function adds
  35. the items into dice_result (22), and returns dice_result.
  36. """
  37. def unlimited_dice(number_of_rolls):
  38.     roll_result = []
  39.     for i in range(number_of_rolls):
  40.         roll_result.append(random.randint(1,6))
  41.         return roll_result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement