简体   繁体   中英

Need help in printing vertically

The task is to have something like this is as the output:

Progress   Trailing   Retriever   Excluded
      *                  *              *                  
                                        *
  • this is a diagram where there are are 4 'headings' and the asterisk represent frequency:
  • I want a way in which I can assign a number say for example for 'progress' and it prints 5 asterisks underneath it and for the rest of the headings:

Here is my attempt:

input:

print("Progress")
x = 0
while x<5:
    print('   *')
    x+=1

output:

Progress
   *
   *
   *
   *
   *

input:

#for next heading 
print("Trailing")
x = 0
while x<2:
    print('   *')
    x+=1

output:

Trailing
   *
   *
  • is there a way I can show them both vertically? just like the intend output or is there another way I can do this where a number is assigned to each header(for the amount of asterisks)

Thanks in advance, I've been trying to find a way for a long time.

Change

print("Trailing")

To

print("Trailing", end='')

And you will not print the default \\n character at the end of the string.

There are ways to move the cursor in a terminal to do it in the way you are probably thinking of but the simplist way is just to print it a line at a time (pseudocode):

print('Progress   Trailing   Retriever   Excluded')
for entry in entries:
    print('  *   ' if entry.progress  else '       ', end='')
    print('  *   ' if entry.trailing  else '       ', end='')
    print('  *   ' if entry.retriever else '       ', end='')
    print('  *   ' if entry.excluded  else '       ') # No end here to add newline

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