0

Max list

x =input(list()) i =0 max =x[0] while i < len(x)-1: if x[i]>=x[i+1]: max =x[i] else: max=x[i+1] i+=1 print('The greatest number is: ', max) Hi, I don't understand where is the error. Thanks

31st Mar 2019, 7:23 PM
Silvio Petix
Silvio Petix - avatar
2 Respostas
+ 4
An example: your list x = 1,3,5,7,2 int max = x[0] //1 start your loop at i = 1; compare max with x[i] if(max < x[i]) --> max = x[i] you don't need else because you don't want to change max if it is larger than x[i] 1 < 3 --> max = 3 3 < 5 --> max = 5 5 < 7 --> max = 7 7 > 2 --> max = 7
31st Mar 2019, 9:02 PM
Denise Roßberg
Denise Roßberg - avatar