[Solved] ValueError: invalid literal for int() with base 10: ” has occurred idk solution


The error occurs when you type in a letter instead of a digit.

Also, you should test for the validity of the user input before trying to delete the number on that index:

from numpy import random

dice = [1, 2, 3, 4, 5, 6]
first = [random.choice(dice) for i in range(5)]
print(first)

while True:
    baggage = []
    retry = random.choice(dice)
    F = input("Choose the dice you want to roll again. (if you don't want to roll again, enter the '0'.)>")
    if F == '0' or len(baggage) > 5 or F.isalpha() or int(F)>5:
        break
    else:
        baggage.append(F)
        del first[int(F)-1]
        first.insert(int(F)-1, retry)

print(first)

solved ValueError: invalid literal for int() with base 10: ” has occurred idk solution