You are viewing our Forum Archives. To view or take place in current topics click here.
Python help! +Rep!
Posted:

Python help! +Rep!Posted:

Frmn
  • Resident Elite
Status: Offline
Joined: Dec 29, 201212Year Member
Posts: 299
Reputation Power: 12
Status: Offline
Joined: Dec 29, 201212Year Member
Posts: 299
Reputation Power: 12
#Initial inventory
inventory=['puppies', 7, 'cats', 5, 'fish', 50]

inventory[1] = inventory[1] +3
inventory[ ] = inventory[ ] *2
print(inventory)

I need to double to amount of fish.

I thought this: inventory[3] = inventory[3] *2 But it doesn't work.. so no idea, any help?
#2. Posted:
UnrealEgg
  • Powerhouse
Status: Offline
Joined: May 30, 201014Year Member
Posts: 438
Reputation Power: 49
Status: Offline
Joined: May 30, 201014Year Member
Posts: 438
Reputation Power: 49
I've not really done any Python, but I presume the array starts at 0 as with most languages.

As you do:
inventory[1] = inventory[1] +3


I guess this sets the puppies to 10. With this in mind, if you wish to double the fish, you would do:

inventory[5] = inventory[5] * 2
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.