700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python中for循环嵌套简写_Python嵌套for循环

python中for循环嵌套简写_Python嵌套for循环

时间:2019-12-04 14:56:37

相关推荐

python中for循环嵌套简写_Python嵌套for循环

我有一个名为!input.txt的文件,其中包含多行,每行是0到10的随机整数。

我想写一个程序来读取文件并计算每个整数(0-10)在文件中出现的次数。例如,如果我的输入文件中有四个“0”、两个“3”和五个“7”,程序将打印如下:Number of occurrences of 0: 4

Number of occurrences of 1: 0

Number of occurrences of 2: 0

Number of occurrences of 3: 2

Number of occurrences of 4: 0

Number of occurrences of 5: 0

Number of occurrences of 6: 0

Number of occurrences of 7: 5

Number of occurrences of 8: 0

Number of occurrences of 9: 0

Number of occurrences of 10: 0

这是我的代码:

^{pr2}$

结果是这样的:Number of occurrences of 0: 4

Number of occurrences of 1: 0

Number of occurrences of 2: 0

Number of occurrences of 3: 0

Number of occurrences of 4: 0

Number of occurrences of 5: 0

Number of occurrences of 6: 0

Number of occurrences of 7: 0

Number of occurrences of 8: 0

Number of occurrences of 9: 0

Number of occurrences of 10: 0

我想我的嵌套for循环有问题,但我不知道是什么问题。请帮忙。在

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。