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
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