Unused variable clean-up

I'm fairly new to programming and I'm learning python. I've defined a function for a dice roll and set it up to roll multiple.

def d20(num):
rolls = 0
for i in range(num):
rolls += randint(1,20)
return rolls


Thonny and my assistant tab gives me a warning:

Line 3: Unused variable 'i'


The code works fine but I like a clean workspace. I was wondering if there is an alternate way to write the range loop or is this just something I need to learn to deal with?

• return sum(randint(1, 20) for _ in range(num)) Oct 5 '20 at 23:27
• I'd turn the thole thing in a roll_dice(num, dice) function that takes d20 as an argument as well.
– Mast
Oct 6 '20 at 3:56