vendredi 15 juillet 2016

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

I have just started coding and don't know much about it. This is my bit of code that tries to cycle through numbers from the for loop to assign num1 and num2. Instead it make a new one called num0. WHAT?!

import random
numbers = {'num1': '', 'num2': ''}

counter = 0
for i in range(0, 2):
    number = random.randint(0, 5)
    counter + 1
    numbers['num' + str(counter)] = number;

print(numbers)




Aucun commentaire:

Enregistrer un commentaire