Python How Can I Make a Counter To Cycle Through a Dictionary Inside a For Loop? -


i have started coding , don't know it. bit of code tries cycle through numbers loop assign num1 , num2. instead make new 1 called num0. what?!

import random numbers = {'num1': '', 'num2': ''}  counter = 0 in range(0, 2):     number = random.randint(0, 5)     counter + 1     numbers['num' + str(counter)] = number;  print(numbers) 

counter + 1 adds 1 value of counter, never stores result assigning result counter. need assign result counter variable, i.e. counter = counter + 1 or more concisely equivalent counter += 1.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

http - Safari render HTML as received -