I'm trying to do a comparison to see if I can continue with a certain function, but I get the 'int' object is not subscriptable.
sect is a dictionary with 4 keys, each key is a list with either 30 or 49 indexes. I just want to check if a certain index minus a number will be more or less than 0.
import time
from collections import defaultdict
def getFile(fn):
fn = open(fn, 'r')
numArr = [line.split()for line in fn]
fn.close()
return numArr
trans = getFile("transactions.txt")
def dictindict(rows, seats):
sections = defaultdict(list)
for key in range(0, 4):
for j in range(1, rows):
sections[key].append(seats)
return sections
tSeats = 96
eSeats = 196
sSeats = 96
tSect = dictindict(40, 96)
eSect = dictindict(50, 196)
sSect = dictindict(50, 96)
def buyTix(trans, sect, sC, rC):
numTix = int(trans[3])
print(sect)
if (sect[sC][rC] - numTix) >= 0: # SELLS THE TICKETS
sect[sC][rC] -= numTix
return sect[sC][rC]
elif (sect[sC][rC] - numTix) < 0 and rC < len(sect[sC]): # CHECK IF ROW IS FULL
return buyTix(trans, sect, sC, rC + 1)
elif (sect[sC][rC] - numTix) < 0 and rC == len(sect[sC]): # CHECK IF SECTION FULL
return buyTix(trans, sect, sC + 1,
for i in range(0, 5):
if trans[i][0] == "BUY":
if trans[i][2] == "E":
eSect = buyTix(trans[i], eSect, 0, 0)
elif trans[i][2] == "T":
tSect = buyTix(trans[i], tSect, 0, 0)
elif trans[i][2] == "S":
sSect = buyTix(trans[i], sSect, 0, 0)
sC and rC are just counters that start at 0.
Thanks.
Aucun commentaire:
Enregistrer un commentaire