-1

i'm making a some code for project, the all i want to do in test function is i want to print out each of 'list_total[y]' values i input

input example

1 # forget this input for now, 

1 # the lines how many input i want to

100, 200 , 300 # i used a map 

then it should be printed out 100, 200 ,300 but instead 'None'

my goal is draw the highest value in each of 'list_total[y]' but seems return value is 'none'

so i also get an error message

'TypeError: 'NoneType' object is not iterable'

when i make a code

like  return print(max(list_total[y]))

here is the code i made below

T = eval(input(": "))


list_total = []


def test(value):

    for x in range(value):
            n = eval(input(": "))
            for y in range(n):
                list_total[y] = list_total.append(list(map(int, input(": ").split())))
                return print(list_total[y])  # make sure code is working




test(T)
ESCoder
  • 15,431
  • 2
  • 19
  • 42
GG OTL
  • 1
  • 2

1 Answers1

0

If you wanted to order them here is how you would do that:

T = eval(input(": "))


list_total = []


def test(value):

    for x in range(value):
        n = eval(input("enter the "+str(x)+"th number: "))
        list_total.append(n)

    print(list_total)         
    return list_total.sort() # make sure code is working

test(T)
print(list_total)

Sample output:

: 4
enter the 0th number: 4
enter the 1th number: 2
enter the 2th number: 1
enter the 3th number: 2
[4, 2, 1, 2]
[1, 2, 2, 4]

But you want to update the array with each entry, in that case you could use a variable to hold the max value going in the list and then compare it with the new entry.

If you want to check the entire array anyway ... the problem you are having are:

  1. you're using the map method in the input you are getting. you don't need that here. the text inside input("helper text") only prompts the user that the program expects an input. you dont have to strip that helper text from input.

  2. have a print and return separately

  3. fix this line : list_total[y] = list_total.append(list(map(int, input(": ").split())))

  4. Inner for loop should not run to range(n) try range(len(list_total))

  5. if you want only the max element to be in the list at any given time:

list_total = list(max(list_total))

Dhruv
  • 645
  • 9
  • 17