Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import random
  2. def UserInput(question):    
  3.     return int(input(question))
  4.  
  5. def RecursiveDiceRoll(numDice, numSides, numRolls, DoDice, total=0):
  6.     if numRolls == 0:
  7.         print("total -",DoDice.__name__,":",total)
  8.     else:
  9.         #print(total)
  10.         for roll in range(numRolls):
  11.             total = DoDice(total, random.choice(range(1,numSides)))
  12.         return RecursiveDiceRoll(numDice, numSides, numRolls - 1, DoDice, total)
  13.    
  14. def RunRecursion():
  15.     numDice  = UserInput("Enter The number of die:")
  16.     numSides = UserInput("Enter the number of sides:")
  17.     numRolls = UserInput("Enter how many rolls:")
  18.     RecursiveDiceRoll(numDice, numSides, numRolls, MulDice)
  19.     RecursiveDiceRoll(numDice, numSides, numRolls, SumDice)
  20.    
  21. def SumDice(total, roll):
  22.     total += roll
  23.     #print(total)
  24.     return total
  25.  
  26. def MulDice(total, roll):
  27.     if total == 0:
  28.         total = 1
  29.     total = total * roll
  30.     #print(total)
  31.     return total
  32.  
  33. RunRecursion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement