在python中,我需要以如下方式汇总count_list中的数据(如直方图):
"""
number | occurence
0 | *
1 | **
2 | ***
3 | **
4 | **
5 | *
6 | *
7 | **
8 | ***
9 | *
10 | **
"""
但是我得到了一个错误的输出:
^{pr2}$这是我的代码:
import random
random_list = []
list_length = 20
while len(random_list) < list_length:
random_list.append(random.randint(0,10))
count_list = [0] * 11
index = 0
while index < len(random_list):
number = random_list[index]
count_list[number] = count_list[number] + 1
index = index + 1
def summerizer():
index = 0
print count_list
print '"'*3
print 'number | occurrence'
while index < len(count_list):
print '%s' %' '*(7),
print index,#the problem is here
print ' | ',#and here
print '%s' %'*'*(count_list[index])
index += 1
print '%s'%'"'*3
summerizer()
此方法使用^{} :
试试这个
输出
^{pr2}$是的,我发现了问题
它来自ide本身!!! 这是UDACITY android应用程序课程中的一个小测验,里面的嵌入式编译器给出了错误的答案。。在
我现在从Android上的pydroid应用程序中尝试过的相同代码也在没有任何改变的情况下给出了我需要的答案
谢谢你们的帮助
Summier()`
相关问题 更多 >
编程相关推荐