Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- I want to do this: When I write !10d6, 10 dices of 6 "bases" are thrown.
- I will return the sum of their indexes.
- '''
- import random
- # AUXILIARY FUNCTION
- def throwDice(command):
- if command[0] != "!":
- print("Command must begin with '!'.")
- else:
- # I will try to find the 'd' character
- didIfindTheDCharacter = False
- indexOfDCharacter = -1000
- for i in range(0, len(command)):
- if command[i] == 'd':
- didIfindTheDCharacter = True
- indexOfDCharacter = i
- break
- # Check if I have found the 'd' character
- if didIfindTheDCharacter == False:
- print("The command begins with the appropriate prefix = '!', but misses the 'd' character.")
- else:
- # The command contains '!' and 'd'
- firstNumberAsString = command[1:indexOfDCharacter]
- secondNumberAsString = command[indexOfDCharacter+1:len(command)]
- firstNumber = int(firstNumberAsString)
- secondNumber = int(secondNumberAsString)
- # Now, I will start the process for producing what I want
- sumOfDiceIndications = 0
- for i in range (0, firstNumber):
- sumOfDiceIndications += random.randint(0, secondNumber)
- return sumOfDiceIndications
- # MAIN FUNCTION
- while 0 == 0:
- command = input("Write command: ")
- print(throwDice(command))
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement