0
ながら使用して、リスト内の最大数を見つける私はこのコードを試してみました:私はそれを修正Howcanは、ループ(パイソン)
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
while numbers[x+1] > numbers[x]:
x = x+1
print numbers[x]
出力は8
のですか?
これを試してみてください:
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ループを使用する必要がありますか? max(numbers)は、必要でない場合に必要なものを提供します。 – chatton
あなたの質問は、ここの質問にはすでに回答があります:http://stackoverflow.com/questions/12766077/python-finding-the-largest-number-in-a-list-using-forloop-or-while-loop –
whileループを使用する必要があります –