0

I have tried this code:

numbers = [1,2,5,8,4,99,3]

x = 0

while numbers[x+1] > numbers[x]: 
    x = x+1

print numbers[x]

The output is 8

Howcan I fix that?

3
  • 2
    do you need to use a while loop? max(numbers) will give you what you need if not. Commented Apr 13, 2017 at 11:57
  • 2
    Your question already has an answer in the question here: stackoverflow.com/questions/12766077/… Commented Apr 13, 2017 at 12:03
  • I must use a while loop Commented Apr 13, 2017 at 12:37

2 Answers 2

1

Try this:

numbers = [1,2,5,8,4,99,3]

x = 0
lar = numbers[x]
while x < len(numbers):
  if numbers[x] > lar:
    lar = numbers[x]
  x = x+1
print lar
Sign up to request clarification or add additional context in comments.

Comments

0
a = [1,2,5,8,4,99,3]
x = 0 
y = 0

while y != len(a):
    if x < a[y]:
        x = a[y]
    y += 1

print x

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.