mardi 9 janvier 2018

"list index out of range" on simple random loop

I typed in this simple while loop, but for some reason it sometimes giving me the list index out of range error. It is strange that it only sometimes gives me the error and the more "Dice" I add, the more likely it is to error. It appears on the Dice_total = Dice_Total + (dice[random.randint(1,6)]) line

import random

Dice = [1, 2, 3, 4, 5, 6]
Dice_Count = int(input())
Dice_Total = 0

while Dice_Count > 0:
    Dice_Total = Dice_Total + (Dice[random.randint(1,6)])
    print (Dice_Total)
    Dice_Count = Dice_Count - 1

print(Dice_Total)




Aucun commentaire:

Enregistrer un commentaire