I've just completed Tatiana Tylosky's tutorial for Python and created my own Python pypet.
In her tutorial, she shows how to do a "for" loop consisting of:
cat = {
'name': 'Fluffy',
'hungry': True,
'weight': 9.5,
'age': 5,
'photo': '(=^o.o^=)__',
}
mouse = {
'name': 'Mouse',
'age': 6,
'weight': 1.5,
'hungry': False,
'photo': '<:3 )~~~~',
}
pets = [cat, mouse]
def feed(pet):
if pet['hungry'] == True:
pet['hungry'] = False
pet['weight'] = pet['weight'] + 1
else:
print 'The Pypet is not hungry!'
for pet in pets:
feed(pet)
print pet
I'd like to know how to repeat this "for" loop so that I feed both the cat and the mouse three times. Most of the Python guides I've read say that you have to do something like:
for i in range(0, 6):
In this case, however, the "for" loop uses the list "pets." So the above code can't be used? What should I do? I've tried some wacky-looking things like:
for pet in pets(1,4):
feed(pet)
print pet
Or:
for pet in range(1,4):
feed(pet)
print pet
Naturally it doesn't work. What should I do to get the "for" loop to repeat?