简体   繁体   中英

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

So I have the data to output like this for example progress 1: *

progress-moduletrailer 4: ****

do_not_progress 6:******

exclude 2: **

But I would want it to show it like this

progress

2:

**

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:

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.

If I understood it correctly a \n between progress, the number and the stars should do the trick. The \n means that a new line is started: Example:

    print(Hello world)

Prints out:

Hello world

but

    print(Hello\nworld)

Prints out:

Hello
World

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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