程序說明:要創建一個空列表並用包含1-500個隨機整數的20個隨機整數填充它,請在單行上打印該列表,並在單獨一行中打印該列表的最大值。最大值功能不能使用。
但然後它要求打印列表中最大值的索引。這是我迄今為止的:
import random
print()
nums = []
for num in range(20):
nums.append(random.randint(1, 500)); sep=''
max = nums[0]
for i in nums:
if i > max:
max = i
print(nums)
print("The maximum value that appears in the list is " + str(max) + ".")
所以我已經解決了最大值問題,但是我很難確定如何從列表中找到最大值的索引。
任何幫助贊賞。