How to use end="" snippet to create a bowling scoreboard
<p>I am trying to create a python program that will read in a Bowling score composed of number of pins knocked out for each toss. I am trying to create an output that looks similar to a bowling scoreboard like this:</p>

<pre><code>  1   2   3   4   5   6   7   8   9    10
+---+---+---+---+---+---+---+---+---+-----+
|8 /|7 2|9 /|X  |- 7|X  |- -|9 /|X  |X 9 /|
| 17| 26| 63| 70| 80| 80| --|100|129|  149|
+---+---+---+---+---+---+---+---+---+-----+
</code></pre>

<p>I have the number of pins knocked down and the scores for each frame in two lists and will iterate through them 10 times to get the ten frames. I have tried different ways, but I am not having much luck. SO far I have something like this (assume that frame is accessing the right value in list).</p>

<pre><code>for frame in range(1, 11):
    if frame &lt;= 9:
        print("  {:d}  \n+---\n|    \n|{:d}\n+---".format(frame,frame),end="")
    else:
        print("  {:d}  \n+-----\n|    \n|{:d}\n+-----".format(frame,frame),end="")
</code></pre>

<p>Do you guys have any suggestions? Thank you so much!</p>

<p>Once you've invoked <code>\n</code>, you can never go back and modify that line again. What you want to do is build 4 strings, and then print all in succession at the end:</p>

<pre><code>def addEndCaps(lines):
    lines[1] += "+"
    lines[2] += "|"
    lines[3] += "|"
    lines[4] += "+"

lines = [ "", "", "", "", "" ]
for frame in range(1,11):
    lines[0] += "  %d " % frame
    lines[1] += "+---"
    lines[2] += "|   "
    lines[3] += "|   "
    lines[4] += "+---"

addEndCaps(lines)
print("\n".join(lines))
</code></pre>

<p>This produces output like this:</p>

<pre><code>  1   2   3   4   5   6   7   8   9   10 
+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
</code></pre>

<p>Obviously you are going to have to do a bit of formatting logic to make sure the hyphens and spaces line up in the case of 2 and 3 digit numbers.</p>

<p>If you really have your heart set on using <code>end=""</code> (i.e. it's for a school assignment), then you'll have to create 5 <code>for</code> loops: one per line of output.</p>

python