1、 已知数列:1,9,1,2,0,5,4,3,2,8,7,6,9,5,3,8,0,1,0,2,4,8,7,9,5,3,1,4,3,9 编写程序,输出各个数字各出现了多少次
时间: 2023-08-19 10:00:48 浏览: 136
好的,我可以帮你解决这个问题。以下是一个简单的程序示例,用于统计给定数列中每个数字出现的次数:
```python
def count_numbers(sequence):
count_dict = {}
for num in sequence:
if num in count_dict:
count_dict[num] += 1
else:
count_dict[num] = 1
return count_dict
sequence = [1, 9, 1, 2, 0, 5, 4, 3, 2, 8, 7, 6, 9, 5, 3, 8, 0, 1, 0, 2, 4, 8, 7, 9, 5, 3, 1, 4, 3, 9]
counts = count_numbers(sequence)
for num, count in counts.items():
print(f"{num}: {count} times")
```
这段代码会输出每个数字以及它们在数列中出现的次数。希望能帮到你!如果有任何疑问,请随时提问。
阅读全文