python - Boolean function to check if a list of ints is in increasing order- Must use a while loop -


how approach this? i've tried different ways , i've far . ex: [1, 2, 5, 7] returns true , [1, 1, 6, 9] returns false. second example doesn't work. returns true though first 2 elements equal. doing wrong?

def increasing(l):     n = len(l)     = 0     while <= n-1:         if l[i] > l[i+1]:             return false         else:             i+=1     return true 

problem lies here

while <= n:     if l[i] > l[i+1]: 

in example, n=4. since array index starts @ 0, list index 0 1 2 3. checking till n=4 incorrect.

then, doing [i+1] checks 5th element.

replace these lines

while < n-1:     if l[i] > l[i+1]: 

this take care of index out of range error

do have use loop here?

no. check python - how check list monotonicity


Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -