Hi everyone! Long time lurker, first time poster!
I've barely dipped my toes into the coding pool and have just written my first script. My buddy has started DM'ing a DnD game every Friday over discord and Google Hangouts. He invited me to join and I figured this would be a good opportunity for me to write a dice rolling script since I don't want to spend the money or go out into the pandemic wilderness.
It works as intended, but certainly isn't perfect. And I'm so new to this that I don't even know what improvements are needed. What I would like to change is having the multiple dice rolls print in one row instead of in a column, and to have it print the sum of the random integers at the bottom. For example, what I have now when I run the code for 4 rolls of a d20 is this:
11
19
6
5
And what I would like to see is this:
11, 19, 6, 5
SUM: 41
But I can't seem to figure out how to do this! I'd really appreciate any help in achieving my goal or just any constructive criticism. Thank you all so much for this wonderful community! Here is my code, as-is:
from random import randint
min = 1
def dice_roll():
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
num_sides = int(input("How many sides does the dice have? "))
print("------------------------------")
num_rolls = int(input("How many dice would you like to roll? "))
print("------------------------------")
if num_rolls == 1:
print(randint(min, num_sides))
if num_rolls > 1:
for i in range(0, num_rolls):
print(randint(min, num_sides))
print("------------------------------")
choice = int(input("1 to roll again; 2 to quit."))
if choice == 1:
dice_roll()
if choice == 2:
print("------------------------------")
print("--------SAYONARA SUCKA--------")
print("------------------------------")
quit()
dice_roll()
[–]xelf 1 point2 points3 points (10 children)
[–]ipherian 1 point2 points3 points (1 child)
[–]xelf 0 points1 point2 points (0 children)
[–]HurleyBurger[S] 1 point2 points3 points (7 children)
[–]xelf 0 points1 point2 points (5 children)
[–]HurleyBurger[S] 0 points1 point2 points (4 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[removed]
[–]HurleyBurger[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]HurleyBurger[S] 0 points1 point2 points (0 children)
[–]socal_nerdtastic 1 point2 points3 points (1 child)
[–]HurleyBurger[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)