[英]Define the draw_histogram() function which is passed a Python dictionary as a parameter
when run my code, it always shows nothing. 运行我的代码时,它始终不显示任何内容。 I am so confused as to what wrong about my code. 我很困惑我的代码有什么问题。 Here is what I coded: 这是我编写的代码:
def draw_histogram(histogram_dict):
all_keys = list(histogram_dict.keys())
all_keys.sort()
for key in all_keys:
stars = "*" * histogram_dict[key]
print(key, ":", stars)
def test_draw_histogram():
print("1.")
draw_histogram({'a': 2, 'c': 7, 'b': 5})
print()
print("2.")
draw_histogram({'a': 0, 'c': 5, 'b': 7, 'f': 0})
And the output should be something like this: 输出应该是这样的:
a: **
b: *****
c: *******
def draw_histogram(histogram_dict):
all_keys = list(histogram_dict.keys())
all_keys.sort()
for key in all_keys:
stars = "*" * histogram_dict[key]
print(key, ":", stars)
def test_draw_histogram():
print("1.")
draw_histogram({'a': 2, 'c': 7, 'b': 5})
print("\n")
print("2.")
draw_histogram({'a': 0, 'c': 5, 'b': 7, 'f': 0})
test_draw_histogram()
You need to call the function you've just defined. 您需要调用刚刚定义的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.