Advertisement
makispaiktis

Bot Command with Dice: "!100d100"

Nov 30th, 2019 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. '''
  2.  
  3. I want to do this: When I write !10d6, 10 dices of 6  "bases" are thrown.
  4. I will return the sum of their indexes.
  5.  
  6. '''
  7.  
  8. import random
  9.  
  10. # AUXILIARY FUNCTION
  11. def throwDice(command):
  12.  
  13.     if command[0] != "!":
  14.         print("Command must begin with '!'.")
  15.     else:
  16.         # I will try to find the 'd' character
  17.         didIfindTheDCharacter = False
  18.         indexOfDCharacter = -1000
  19.         for i in range(0, len(command)):
  20.             if command[i] == 'd':
  21.                 didIfindTheDCharacter = True
  22.                 indexOfDCharacter = i
  23.                 break
  24.  
  25.         # Check if I have found the 'd' character
  26.         if didIfindTheDCharacter == False:
  27.             print("The command begins with the appropriate prefix = '!', but misses the 'd' character.")
  28.         else:
  29.             # The command contains '!' and 'd'
  30.             firstNumberAsString = command[1:indexOfDCharacter]
  31.             secondNumberAsString = command[indexOfDCharacter+1:len(command)]
  32.             firstNumber = int(firstNumberAsString)
  33.             secondNumber = int(secondNumberAsString)
  34.  
  35.             # Now, I will start the process for producing what I want
  36.             sumOfDiceIndications = 0
  37.             for i in range (0, firstNumber):
  38.                 sumOfDiceIndications += random.randint(0, secondNumber)
  39.  
  40.             return sumOfDiceIndications
  41.  
  42. # MAIN FUNCTION
  43. while 0 == 0:
  44.     command = input("Write command: ")
  45.     print(throwDice(command))
  46.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement