{"id":173,"date":"2021-03-14T17:52:38","date_gmt":"2021-03-14T17:52:38","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/?page_id=173"},"modified":"2023-02-07T09:11:15","modified_gmt":"2023-02-07T09:11:15","slug":"printing-arrays","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/national-5\/printing-arrays\/","title":{"rendered":"Printing Arrays"},"content":{"rendered":"<p>The contents of arrays can be printed using a loop.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# --- Display names and scores ---\r\nfor index in range(20):\r\n    print(f&quot;{name&#x5B;index]} scored {score&#x5B;index]}&quot;) \r\n#\r\n<\/pre>\n<p>Index values start at 0, but people usually start counting at 1. If printing the index value, it can be adjusted (index+1) to make it more user friendly:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# --- Display names and scores ---\r\nfor index in range(len(name)):\r\n    print(f&quot;Student {index+1} = {name&#x5B;index]} scored {score&#x5B;index]}&quot;) \r\n#\r\n<\/pre>\n<h1>Printing Tables\/Columns<\/h1>\n<p>Specifying field widths will give need tables\/columns of data:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# --- Display names and scores ---\r\nprint(&quot;No.  Name               Score&quot;)\r\nfor index in range(len(name)):\r\n    print(f&quot;{index+1:3} {name&#x5B;index]:20} {score&#x5B;index]:5}&quot;) \r\n#\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The contents of arrays can be printed using a loop. # &#8212; Display names and scores &#8212; for index in range(20): print(f&quot;{name&#x5B;index]} scored {score&#x5B;index]}&quot;) # Index values start at 0, but people usually start counting at 1. If printing the index value, it can be adjusted (index+1) to make it more user friendly: # &#8212; Display names and scores &#8212; for index in range(len(name)): print(f&quot;Student {index+1} = {name&#x5B;index]} scored {score&#x5B;index]}&quot;)<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/national-5\/printing-arrays\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":337,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-173","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":8,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/173\/revisions"}],"predecessor-version":[{"id":741,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/173\/revisions\/741"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/337"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/media?parent=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}