Here is what I'm trying to do, I return a set of values from a web request
[[1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1], [11, 0, 1], [12, 0, 1], [13, 0, 1], [14, 0, 1], [15, 4431, 1], [16, 0, 1], [17, 0, 1]]
The first number can go from either 1 to 1 or 1 to 18. There can also be between 1 and 18 lines in the array (this is causing the issue) I need a statement that the number of returns doesnt matter. So that I could get 1 value such a [1,0,1] or to values [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1].
I then want to take the second number and run if statements off of it. Here is my code so far, I just cannot seem to get it to run right. Im sure its an easy fix but my hair wants to fall out. Any help is greatly appreciated.
I put the print statement in there just to make sure I'm not crazy when i was coding. It works without the if, so I'm lost... This code breaks at the moment where the return array is different. Say my first city has 20 available troops thus returning [20][1] works, but for city 2 it has 12 types of available troops so using [20][1] in a if statement break it. I have tried multiple different formats of the below if, but still craps out if I use an array value that doesnt exist. Thanks guys
#Get troop counts
troopsnumber = getTroopsAvailable(city)
available_troops = []
for troops in troopsnumber:
available_troops.append(troops)
barracks = len(available_troops)
print available_troops
if available_troops[14][1] > 1:
soldier = available_troops[14][1]
soldiernum = soldier
print "You have ", soldiernum, " many soldiers"
if available_troops[19][1] > 1:
soldier1 = available_troops[19][1]
soldier1num = soldier1
print "You have", soldier1num, " many grenaders"

New Topic/Question
Reply



MultiQuote






|