{"id":438,"date":"2021-03-17T08:47:28","date_gmt":"2021-03-17T08:47:28","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/?page_id=430"},"modified":"2022-05-25T13:36:54","modified_gmt":"2022-05-25T12:36:54","slug":"running-totals","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/nat4\/running-totals\/","title":{"rendered":"Running Totals"},"content":{"rendered":"<p>Running Totals are used to add a list of numbers.<\/p>\n<h1>General Algorithm<\/h1>\n<pre>set total to zero\r\nfor each value in list\r\n    add value to the total\r\nnext value<\/pre>\n<h1>Adding numbers as they are entered (Nat4)<\/h1>\n<pre class=\"brush: python; highlight: [2,7]; title: ; notranslate\" title=\"\">#\r\ntotalAge = 0\r\n\r\nfor pupil in range(5):\r\n\r\n    age = int(input('Enter age:'))\r\n    totalAge = totalAge + age\r\n\r\nprint(f'Total age = {totalAge}')\r\n\r\naverageAge = totalAge \/ 5\r\nprint(f'Average = {averageAge}')\r\n#\r\n\r\n<\/pre>\n<h1>Adding numbers in an array (Nat5)<\/h1>\n<pre class=\"brush: python; highlight: [4,8]; title: ; notranslate\" title=\"\">#\r\nscores = &#x5B;4,7,9,4,8,2,7]\r\n\r\ntotal = 0\r\n\r\nfor player in range(len(scores)): # or range(7):\r\n\r\n    total += scores&#x5B;player]\r\n \r\n#<\/pre>\n<h1>Adding numbers in an array of records (Higher)<\/h1>\n<h2>Traversing array by index:<\/h2>\n<pre class=\"brush: python; highlight: [2,6]; title: ; notranslate\" title=\"\">\r\n#\r\ntotal = 0\r\n\r\nfor student in range(len(students)):\r\n\r\n    total += students&#x5B;student].mark\r\n#<\/pre>\n<h2>Traversing array by values:<\/h2>\n<pre class=\"brush: python; highlight: [2,6]; title: ; notranslate\" title=\"\">#\r\ntotal = 0\r\n\r\nfor student in students:\r\n\r\n    total += student.mark\r\n#<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Running Totals are used to add a list of numbers. General Algorithm set total to zero for each value in list add value to the total next value Adding numbers as they are entered (Nat4) # totalAge = 0 for pupil in range(5): age = int(input(&#8216;Enter age:&#8217;)) totalAge = totalAge + age print(f&#8217;Total age = {totalAge}&#8217;) averageAge = totalAge \/ 5 print(f&#8217;Average = {averageAge}&#8217;) # Adding numbers in an array<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/nat4\/running-totals\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":297,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-438","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/438","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=438"}],"version-history":[{"count":12,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/438\/revisions"}],"predecessor-version":[{"id":734,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/438\/revisions\/734"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/297"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/media?parent=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}