The below rolls dice in python. I’ve long loved python for dice-rolling―having created a now defunct twitterbot and a mastodon bot―it was nice to write this up briefly as I’m working on re-re-re-learning python.
#!/usr/bin/python3 from random import randint total_dice = int(input('How many dice? ')) dice_val = int(input("How many sides? ")) rolls = [] high_roll = 0 low_roll = 0 for i in range(total_dice): roll = randint(1, dice_val) rolls.append(roll) nums = len(rolls) print("") print("Roll #\tRoll") print("------------------") for i in range(nums): print("#" + str(i+1) + ":\t" + str(rolls[i])) print("------------------") print("Highest: " + str(max(rolls))) print("Lowest: " + str(min(rolls))) print("------------------") print("TOTAL: " + str(sum(rolls)))
Output looks like the below:
How many dice? 20 How many sides? 20 Roll # Roll ------------------ #1: 8 #2: 6 #3: 18 #4: 7 #5: 14 #6: 7 #7: 6 #8: 12 #9: 2 #10: 10 #11: 2 #12: 13 #13: 3 #14: 10 #15: 20 #16: 5 #17: 6 #18: 19 #19: 1 #20: 15 ------------------ Highest: 20 Lowest: 1 ------------------ TOTAL: 184
Wonderful fun.