使用while循环(蟒蛇)
问题描述:
我已经试过这个代码列表中找到数量最多:使用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我解决这个问题?
答
试试这个:
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
答
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
你需要使用while循环?最大(数字)会给你你需要的东西,如果没有。 – chatton
您的问题已经在这里的问题中有一个答案:http://stackoverflow.com/questions/12766077/python-finding-the-largest-number-in-a-list-using-forloop-or-while-loop –
我必须使用一个while循环 –