i need to find a min and amx of the table and so far i can do the min of row 1 but nothing after that

--------------------------------------------------------------------
|Name  |     A      |     B     |     C      |    D     |    E      |
--------------------------------------------------------------------
|  1   |    1.0     |    2.0    |    3.0     |   4.0    |   5.0     |
|  2   |    6.0     |    7.0    |    8.0     |   9.0    |   0.0     |
|  3   |    1.1     |    2.2    |    3.3     |   0.1    |   0.3     |
--------------------------------------------------------------------




def minimum(y,l):
    for y in l:
        if y == 1:
            i= 0
            w=(l[i],l[i+1],l[i+2],l[i+3],l[i+4])
            a= min(l[i],l[i+1],l[i+2],l[i+3],l[i+4])
        eli
        f y == 2:
            i = 5
            w=(l[i],l[i+1],l[i+2],l[i+3],l[i+4])
            a= min(l[i],l[i+1],l[i+2],l[i+3],l[i+4])


        return a





def menu(x,l): 
    if x == 1:
        make_table(l)
    if x == 2:
        y = input("enter a row (as a number) or a column (as an uppercase letter)")
        if y in [ '1','2','3']:
            mini = minimum(y, l)
            print("Minimum is:", mini)
    if x == 3:
        print ('bye')

Recommended Answers

All 2 Replies

join lines 18 and 19 in your code please

A few pieces of advice:

  • Never use certain letters for variable names, especially l (lowercase 'L') and O (uppercase 'o'). They are too easily misread as the numbers 1 and 0, especially when scanning the code quickly.
  • Using a for: loop and then breaking down the values of the loop into separate conditions (the so-called 'for-case' or 'for-if' anti-pattern) makes no sense; you are better off either finding a way to consolidate the conditions, or else eliminate the loop.
  • When getting the mininmum or maximum of a list, the easiest (if not necessarily the most efficent) way to find the value in question is to sort a copy of the list. In the case of a multi-dimensional list, merge the lists into a single copy first, then sort.

Taking this last piece of advice into account, the solution should be trivial:

t = [[1.0, 2.0, 3.0, 4.0, 5.0],
     [6.0, 7.0, 8.0, 9.0, 0.0],
     [1.1, 2.2, 3.3, 0.1, 0.3]]

def minmax(table, row):
    table[row].sort()
    return table[row][0], table[row][-1]

min, max = minmax(t, 1)

print(min)
print(max)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.