Advertisement
nosthemerc

Dice

Dec 29th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. import random
  2.  
  3. # Most of this stuff is commented out.  
  4. # Part of the reason is through an eXtreMe programming approach and I wanted to preserve my thought process which currently is defeloped for functions.
  5. # Part of it is also that I apperently don't kow how the 'return' script works between functions.
  6. # So preserving this part of the code may also aid in showing progress as a programmer once I'm more fluent in the logic.
  7. # I'd like to return to this code one day to make it work through functions.
  8. # Until then, copy-pasting everything into the Main() function seems to work just fine.
  9.  
  10. #def DefineDieType():
  11. #   die_sides = int(input("How many sides to the die? >"))
  12. #   return die_sides
  13. #
  14. #def RollDie():
  15. #   roll = random.randint(1, die_sides)
  16. #   return roll
  17. #
  18. #def RollMultipleDice():
  19. #   number_of_dice = int(input("How many dice are being rolled? >"))
  20. #   dice_rolled = 0
  21. #
  22. #   global total_from_dice
  23. #
  24. #   while dice_rolled < number_of_dice:
  25. #       RollDie()
  26. #       total_from_dice += roll
  27. #       dice_rolled +=1
  28. #
  29. #def AddModifier():
  30. #   modifier = int(input("What is the modifier? >"))
  31. #   global total_from_dice
  32. #   total_from_dice += modifier
  33.  
  34. def Main():
  35.     while True:
  36.         total_from_dice = 0
  37.  
  38.         die_sides = int(input("How many sides to the die? >"))
  39.         number_of_dice = int(input("How many dice are being rolled? >"))
  40.         dice_rolled = 0
  41.  
  42.         while dice_rolled < number_of_dice:
  43.             total_from_dice += random.randint(1, die_sides)
  44.             dice_rolled +=1
  45.  
  46.         modifier = int(input("What is the modifier? >"))
  47.         total_from_dice += modifier
  48.  
  49.         print("\n Result: ", total_from_dice)
  50.  
  51. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement