Can’t understand what the flaw in my logic is:

Assuming you just need the largest number, removing the unwanted code. You do not need the nested loop here. Update your function to:

def largest_num(values,n,b):
    a = 0;
    start = 0;
    for i in range(n - 1):
            if(values[i+1] > values[i]:
                largest = values[i+1]
                largest = values[i]

You may achieve the same using built-in max() as:

>>> max([1, 5, 2, 10, 4])

Browse More Popular Posts

Leave a Comment