This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Trying to make a dice roller for DND character sheets. Using the formula of roll 4d6, sort the numbers, delete the lowest number, add the numbers together, put the totaled number into an empty list, repeat 6 times, output the list of totaled numbers. everything works except when I add the totaled number to the list using .append or .insert the list index is always overwriting [0]. I have marked the section I believe is my issue with ~
received output:
[11]
[9]
[15]
[16]
[8]
[13]
stats rolled: [13]
[8]
[17]
[12]
[13]
[11]
[14]
stats rolled: [14]
[12]
[14]
[8]
[9]
[13]
[12]
stats rolled: [12]
alignment: 3
code:
import random
def statsroll():
  rolled_dice =[]
  Total_roll = []
  tallytemp = 0
  for y in range(0,6): #roll for the 6 base stats in dnd
    tally = 0
    rolled_dice.clear()
    Total_roll.clear() #clear all variables from last loop
    for x in range(0,4): #roll 4d6 and add values to list
      rolled_dice.append(random.randint(1,6))
    rolled_dice.sort()
    #print('dice rolled: ', rolled_dice) #debug dice rolls
    rolled_dice.pop(0) #delete the lowest number according to sort
    #print('drop the lowest: ', rolled_dice) #debug lowest roll deletion
#~
   for u in range(0, len(rolled_dice)): #add the dice rolls together
      tally = tally rolled_dice[u]
      tallytemp = tally
    Total_roll.append(tallytemp)
    #print('index', Total_roll.index(tallytemp)) #debug
    print(Total_roll) #debug
#~
  print('stats rolled:', Total_roll) #expected output: list, 6 numbers, in the range of 3~18
print('##########')
for b in range(0,3): #produce multiple dicesets to pick from
statsroll()
print('alignment:', random.randint(1,9)) #random alignment picker
Subreddit
Post Details
- Posted
- 6 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...