2017-04-13 171 views
0

我已經試過這個代碼列表中找到數量最多:使用while循環(蟒蛇)

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

x = 0 

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

print numbers[x] 

輸出是8

Howcan我解決這個問題?

+2

你需要使用while循環?最大(數字)會給你你需要的東西,如果沒有。 – chatton

+2

您的問題已經在這裏的問題中有一個答案:http://stackoverflow.com/questions/12766077/python-finding-the-largest-number-in-a-list-using-forloop-or-while-loop –

+0

我必須使用一個while循環 –

回答

0

試試這個:

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