python 3.x - Dice Rolling Simulator -
i making dice rolling simulator in python play dnd. new python please don't make fun of me if code bad.
import random while 1 == 1: dice = input("what kind of dice roll?: ") # asking kind of dice roll (d20, d12, d10, etc.) number = int(input("how many times?: ")) # number of times program roll dice if dice == 'd20': print(random.randint(1,21) * number) elif dice == 'd12': print(random.randint(1,13) * number) elif dice == 'd10': print(random.randint(1,11) * number) elif dice == 'd8': print(random.randint(1,9) * number) elif dice == 'd6': print(random.randint(1,7) * number) elif dice == 'd4': print(random.randint(1,5) * number) elif dice == 'd100': print(random.randint(1,101) * number) elif dice == 'help': print("d100, d20, d12, d10, d8, d6, d4, help, quit") elif dice == 'quit': break else: print("that's not option. type list of different commands.") quit()
my original attention let , not make number variable, brother reminded me weapons have multiple rolls , instead of rolling more once, want have input asking how many times roll dice. problem code right randomize number , then times two. want times number of different integers , add them together.
maybe use for
-loop , iterate on number
of times user wants roll dice, while saving list display each roll of die.
for example, first die may this:
rolls = [] if dice == 'd20': roll in range(number): rolls.append(random.randint(1,21)) print('rolls: ', ', '.join([str(roll) roll in rolls])) print('total:', sum(rolls))
example output:
what kind of dice roll?: d20 how many times?: 2 rolls: 10, 15 total: 25
Comments
Post a Comment