简体   繁体   English

我如何将我的直方图垂直转换为 output 数据?

[英]How would I get my histogram to output the data vertically?

So I have the data to output like this for example progress 1: *所以我有 output 的数据,例如进度 1:*

progress-moduletrailer 4: ****进度模块预告片 4:****

do_not_progress 6:****** do_not_progress 6:******

exclude 2: **排除2:**

But I would want it to show it like this但我希望它像这样显示

progress进步

2: 2:

** **

etc ETC

I would appreciate any help with this, very stuck.我将不胜感激,非常困难。

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")

Try defining the separator argument of the print function and using an f-string format as such:尝试定义打印 function 的分隔符参数并使用f-string格式,如下所示:

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

FYI: The default separator is a single space, changing it to a new line (or 2 new lines if you so wish) can be done through each function call.仅供参考:默认分隔符是一个空格,可以通过每个 function 调用将其更改为新行(或 2 个新行,如果您愿意)。

If I understood it correctly a \n between progress, the number and the stars should do the trick.如果我正确理解了进度之间的\n ,那么数字和星星应该可以解决问题。 The \n means that a new line is started: Example: \n 表示开始新行: 示例:

    print(Hello world)

Prints out:打印出来:

Hello world

but

    print(Hello\nworld)

Prints out:打印出来:

Hello
World

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM