Nest list doesn't become integer (Python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Nest list doesn't become integer (Python)

A = [] B = [] C = [] D = [] E = [] F = [] data = [A, B, C, D, E, F] bus = ['bus A', 'bus B', 'bus C', 'bus D', 'bus E', 'bus F'] dataType = input('Do you want to use the default data (d) or enter your own? (o)') if dataType == 'o': for i in range(6): print('Please enter the punctuality of ' + bus[i] + ' and separate them with a space') punctuality = input(int()) punctuality = punctuality.split(' ') data[i].append(punctuality) print(data) Hi so im having an issue with this and im really confused as to why the output for print data comes out as a string something like this [['2'], ['2 2 2 2 2'], ['2 2 2 2 2'], ['2 2 2 2 2'], ['2 2 2 2 2'], ['2 2 2 2 2 2']] even though i specifically set the input to integer. This causes problems further down: for i in range(6): for j in data[i]: if j < 0: lateData[i].append(j) print('The number of late arrivals for ' + bus[i] + ' is', len(lateData[i]) TypeError: '<' not supported between instances of 'str' and 'int' any help would be greatly appreciated, thanks!

25th Aug 2020, 3:32 AM
Fellaman
Fellaman - avatar
4 Answers
0
try this 👇👇 if int(j)<0:
25th Aug 2020, 3:45 AM
Sangeetha
0
Thanks for the reply, @Sangeetha, but this is the error i got: TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
25th Aug 2020, 3:48 AM
Fellaman
Fellaman - avatar
0
Fellaman y can't you post over all clear code it helps me detach the error
25th Aug 2020, 4:01 AM
Sangeetha
0
@Sangeetha, ok here is my entire code: #input validations import numpy A = [] B = [] C = [] D = [] E = [] F = [] data = [A, B, C, D, E, F] bus = ['bus A', 'bus B', 'bus C', 'bus D', 'bus E', 'bus F'] dataType = input('Do you want to use the default data (d) or enter your own? (o)') if dataType == 'o': for i in range(6): print('Please enter the punctuality of ' + bus[i] + ' and separate them with a space') punctuality = [int(i) for i in (input()).split(' ')] data[i].append(punctuality) elif dataType == 'd': A = [0, 0, 0, 2, 2, 4, 0, 3, 4, -2, -5, 0, 0, 3, 4, -1, 8, 1, 1, -2] B = [0, 1, 0, 0, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0] C = [2, 0, -1, -1, -2, -2, -3, -1, 0, 0, -2, 0, 1, 1, 1, 1, -1, -1, 2, -2] D = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0] E = [-1, -1, -1, -2, -4, -10, -2, 0, 0, 0, 0, 1, 2, -3, 1, 1, 3, -1, 0, 0] F = [0, -5, -5, -5, -4, -3, -5, 0, 0, 0, 0, -2, -3, 1, 1, 1, 0, 0, -2, -5] data = [A, B, C, D, E, F] lateA = [] lateB = [] lateC = [] lateD = [] lateE = [] lateF = [] lateData = [lateA, lateB, lateC, lateD, lateE, lateF] for i in range(6): for j in data[i]: if int(j) < 0: lateData[i].append(j) print('The number of late arrivals for ' + bus[i] + ' is', len(lateData[i])) for i in range(6): if numpy.mean(data[i]) < 0: print('The average number of minutes late for ' + bus[i] + ' is', str(numpy.mean(data[i])).replace('-', '')) mostLate = len(lateData[0]), len(lateData[1]), len(lateData[2]), len(lateData[3]), len(lateData[4]), len(lateData[5]) latestBus = [] for i in range(6): if mostLate[i] == sorted(mostLate)[-1]: latestBus.append(i) i = 0 while i < len(latestBus): print('The bus with the most number of days late was', bus[latestBus[i]]) i = i + 1 for i in range(6): if len(lateData[i]) == 0: print('The average number of minutes late for', bus[i], "is 0") else: pri
25th Aug 2020, 4:03 AM
Fellaman
Fellaman - avatar