This is my code:
lowMess=input('A\n')
if 'dice(' in lowMess:
diceLen = len(lowMess)
dice = []
for x in range (5,diceLen):
if x.isnumeric():
dice.append(x)
print(dice)
This is my code:
lowMess=input('A\n')
if 'dice(' in lowMess:
diceLen = len(lowMess)
dice = []
for x in range (5,diceLen):
if x.isnumeric():
dice.append(x)
print(dice)
Your x
is an integer (taken from range(5, diceLen)
) and has nothing to do with the input, other than that it could be used as an index in the input string. So you would want to make that access in the input string:
digit = lowMess[x]
Then continue with the check. As noted in comments, for checking whether a character is a digit, isnumeric
is not the right tool. Use isdecimal
:
if digit.isdecimal():
...and convert to integer:
dice.append(int(digit))
All this can be done with list comprehension:
dice = [int(digit) for digit in lowMess if digit.isdecimal()]