0

For an assignment I've been given one of the functions we have to make is display_players, we were given this list and I'm struggling with understanding how to correctly format the list so it displays like the sample output.

Ray Holt                   5  5  0  0     100      15
Jessica Jones             12  0  6  6      50       6
Johnny Rose                6  2  0  4      20      10
Gina Linetti               7  4  0  3     300      15

Sample Output:

===========================================================
-                       Player Summary                    -
===========================================================
-                           P   W   L   D   Chips   Score -
-----------------------------------------------------------
- Ray Holt                  5   5   0   0   100        15 -
-----------------------------------------------------------
- Jessica Jones            12   0   6   6    50         6 -
-----------------------------------------------------------
- Johnny Rose               6   2   0   4    20        10 -
-----------------------------------------------------------
- Gina Linetti              7   4   0   3   300        15 -
-----------------------------------------------------------
===========================================================

I know the very basics of using <, >, ^ etc. when it comes to creating spacing, however I'm not really sure how to do it on such a scale. Any tips would be greatly appreciated :)

EDIT: I'm not allowed to use any libraries for this assigment sadly

  • 4
    Does this answer your question? [Printing Lists as Tabular Data](https://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data) – wjandrea Nov 04 '19 at 19:50
  • 1
    If you want to avoid additional libraries you could simply take advantage of Python's String Format Capabilities - https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces – h0r53 Nov 04 '19 at 19:52

1 Answers1

0

Since it is an assignment, I won't give you a full working example but here is the Python page on string formatting:

https://docs.python.org/3/library/string.html#format-examples

It's a lot to look at, but go on down to the examples section. In "Aligning the text and specifying a width" is a good place to start. You can loop through each of the "players" and for each one print their values with the proper alignment and a constant width that is sufficient for the size of the field.

It is always good to do things incrementally. So loop through and just print each of their names on a line. Run it, verify. Then print the "P" value, run, verify. Then start adjusting the width, alignment, and build up from there.

EDIT: This is assuming you are using Python 3

ufoxDan
  • 559
  • 2
  • 12
  • 2
    Your link is for Python 2. For Python 3 go to: https://docs.python.org/3/library/string.html#format-examples – dtauxe Nov 04 '19 at 21:10