【发布时间】:2019-08-07 09:46:11
【问题描述】:
我正在用 python 编写一个程序,提示用户输入多个整数值。该程序将需要存储整数,计算每个整数的频率并显示频率。 (要存储的元素数量可以是任何...5、6、7) 我尝试从 2 开始嵌套循环,第一个只是为了在列表中添加数字,但我知道实现计数器很热
输出应该是这样的 print(Integer value, "occurs", frequency, "times)
input_list = int(input("Input the number of elements to be stored in a list: "))
list = []
for x in range(input_list):
list.append(input("Element - 0: "))
list.append(input("Element - 1: "))
list.append(input("Element - 2: "))
list.append(input("Element - 3: "))
list.append(input("Element - 4: "))
print("The frequency of all elements of the list:\n")
for y in counter(list)
counter = 0
【问题讨论】:
标签: python-3.x list dictionary counter frequency