Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def UserInput(question):
- return int(input(question))
- def RecursiveDiceRoll(numDice, numSides, numRolls, DoDice, total=0):
- if numRolls == 0:
- print("total -",DoDice.__name__,":",total)
- else:
- #print(total)
- for roll in range(numRolls):
- total = DoDice(total, random.choice(range(1,numSides)))
- return RecursiveDiceRoll(numDice, numSides, numRolls - 1, DoDice, total)
- def RunRecursion():
- numDice = UserInput("Enter The number of die:")
- numSides = UserInput("Enter the number of sides:")
- numRolls = UserInput("Enter how many rolls:")
- RecursiveDiceRoll(numDice, numSides, numRolls, MulDice)
- RecursiveDiceRoll(numDice, numSides, numRolls, SumDice)
- def SumDice(total, roll):
- total += roll
- #print(total)
- return total
- def MulDice(total, roll):
- if total == 0:
- total = 1
- total = total * roll
- #print(total)
- return total
- RunRecursion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement