如何获得直方图以垂直输出数据?

例如,我有要输出的数据 进度1:*

progress-moduletrailer 4:****

do_not_progress 6:******

排除2:**

但是我希望它像这样显示

进度

2:

**

对此我将不胜感激,非常棘手。

print("Progress",Progress,":",end= " ")
for i in range (Progress):
    print("*",end = " ")
print("\n")

print("Progress_module_trailer",Progress_module_trailer,end= " ")
for i in range (Progress_module_trailer):
    print("*",end = " ")
print("\n")

print("Do_not_progress_module_trailer",Do_not_progress_module_trailer,end= " ")
for i in range (Do_not_progress_module_trailer):
    print("*",end = " ")
print("\n")

print("Exclude",Exclude,end= " ")
for i in range (Exclude):
    print("*",end = " ")
print("\n")

print(Progress+Progress_module_trailer+Do_not_progress_module_trailer+Exclude,"Number of students in total")
yitianshici 回答:如何获得直方图以垂直输出数据?

尝试定义打印函数的分隔符参数,并使用f-string格式,例如:

print("Progress",f"{Progress}:",sep='\n'))

仅供参考:默认的分隔符为单个空格,可以通过每个函数调用将其更改为新行(或者,如果需要,可以更改为2行)。

,

如果我正确理解进度之间的\n,数字和星星应该可以解决问题! \ n表示新行开始。 示例:

    print(Hello world)

打印出:

Hello world

但是

    print(Hello\nworld)

打印出:

Hello
World
本文链接:https://www.f2er.com/3077549.html

大家都在问