【发布时间】:2021-02-23 15:26:06
【问题描述】:
这是我的程序,
empty_list = []
max_no = 0
for i in range(5):
input_no = int(input("Enter a number: "))
empty_list.append(input_no)
for x in empty_list:
if x > max_no:
max_no = x
high = empty_list.index(max_no)
print ([empty_list[high]])
示例列表:[4, 3, 6, 9, 9]
示例输出:[9]
如何更改我的程序以打印出出现在同一个列表中的最大数量的所有实例?
预期输出:[9, 9]
【问题讨论】:
-
print out all the largest numbers that occur more than once是什么意思如果给你[1,1,1,1,5]呢? -
您想要答案 (2, 9) 还是 [9, 9]? (2, 9) 表示 9 出现 2 次span>
-
@taesu 我想打印出
[5]。 -
@PascalFares
[9, 9]。基本上是数组中最大数的所有实例。
标签: python arrays python-3.x