{"id":1109,"date":"2016-03-30T20:17:08","date_gmt":"2016-03-30T20:17:08","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/?p=1109"},"modified":"2016-03-31T09:30:07","modified_gmt":"2016-03-31T09:30:07","slug":"national-5-computational-constructs-revision","status":"publish","type":"post","link":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/2016\/03\/30\/national-5-computational-constructs-revision\/","title":{"rendered":"National 5 &#8211; Computational Constructs (Revision)"},"content":{"rendered":"<table>\n<tbody>\n<tr>\n<td width=\"650\">Expressions to assign values to variables<\/p>\n<p><strong><em>Number=0<\/em><\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"650\">Expressions to return values using <strong>arithmetic<\/strong> operations (+ &#8211; * \/ ^ mod)<\/p>\n<p><strong><em>Average=total\/5<\/em><\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"650\">Execution of lines of code in sequence demonstrating input \u2013 process- output<\/p>\n<p>1.<strong> SEND<\/strong> \u201cEnter First Number\u201d <strong>TO DISPLAY<\/strong><\/p>\n<p>2. <strong>RECEIVE first_number<\/strong> <strong>FROM (INTEGER) KEYBOARD <\/strong><em>[input]<\/em><\/p>\n<p>3. <strong>SEND<\/strong> \u201cEnter Second Number\u201d <strong>TO DISPLAY<\/strong><\/p>\n<p>4. <strong>RECEIVE<\/strong> <strong>second_number<\/strong> <strong>FROM (INTEGER) KEYBOARD\u00a0<\/strong><em>[input]<\/em><\/p>\n<p>5.<strong> SET<\/strong> <strong>total TO<\/strong> first_number + second_number<em> [process]<\/em><\/p>\n<p>6. <strong>SEND<\/strong> <strong>total<\/strong> <strong>TO DISPLAY <\/strong><em>[output]<\/em><\/td>\n<\/tr>\n<tr>\n<td width=\"650\">Expressions to <strong>concatenate strings<\/strong> and arrays using the &amp; operator<\/p>\n<p>Bob Smith is an example of <strong>concatenation<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong><em>firstName=\u201dBob\u201d<\/em><\/strong><\/p>\n<p><strong><em>secondName=\u201dSmith\u201d<\/em><\/strong><\/p>\n<p><strong><em>print(firstName + secondName)<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>BobSmith<\/td>\n<\/tr>\n<tr>\n<td width=\"650\">Use of selection constructs including <strong>simple <\/strong>and <strong>complex conditional statements<\/strong> and logical operators.<\/p>\n<p>This is a simple statement as there is one conditions<\/p>\n<p><strong>1. IF pupil_mark &gt;=50 THEN <\/strong><\/p>\n<p><strong>2. \u00a0 \u00a0SEND pass message TO DISPLAY<\/strong><\/p>\n<p><strong>3. ELSE<\/strong><\/p>\n<p><strong>4. SEND fail message TO DISPLAY<\/strong><\/p>\n<p><strong>5. END IF<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p>This is a complex statement as there are two conditions<\/p>\n<p><strong>1. IF pupil_mark &gt;=50\u00a0<\/strong><strong>AND assessments_mark = 100 THEN <\/strong><\/p>\n<p><strong>2. \u00a0 \u00a0 SEND pass message TO DISPLAY<\/strong><\/p>\n<p><strong>3. ELSE<\/strong><\/p>\n<p><strong>4. \u00a0 \u00a0 \u00a0SEND fail message TO DISPLAY<\/strong><\/p>\n<p><strong>5. END IF<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"650\"><strong>Iteration<\/strong> and <strong>repetition<\/strong> using fixed and conditional loops<\/p>\n<p><strong>Fixed loop<\/strong> below as it will loop a fixed number of times depending on the users answer<\/p>\n<p><strong><em>number=int(input(\u201cHow many smart phones?\u201d))<\/em><\/strong><\/p>\n<p><strong><em>total=0.0<\/em><\/strong><\/p>\n<p><strong><em>for phone in range(number):<\/em><\/strong><\/p>\n<p><strong><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Name=input(\u201cPlease enter the name of the smart phone:\u201d)<\/em><\/strong><\/p>\n<p><strong><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cost=float(input(\u201cPlease enter the cost of the smart phone:\u201d))<\/em><\/strong><\/p>\n<p><strong><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 total=total + cost<\/em><\/strong><\/p>\n<p><strong><em>print(\u201cTotal cost = \u201c,total)<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Below is a <strong>Conditional Loop<\/strong> as it depends whether the user has any money left.<\/p>\n<p><strong><em>money=int(input(\u201cPlease enter your pocket money in \u00a3\u201d))<\/em><\/strong><\/p>\n<p><strong><em>while money&gt;0:<\/em><\/strong><\/p>\n<p><strong><em>\u00a0 \u00a0 name=input(\u201cPlease enter the name of the CD you want to buy\u201d)<\/em><\/strong><\/p>\n<p><strong><em>\u00a0 \u00a0 cost=float(input(\u201cPlease enter the cost of the CD\u201d))<\/em><\/strong><\/p>\n<p><strong><em>\u00a0 \u00a0 money=money-cost<\/em><\/strong><\/p>\n<p><strong><em>print(\u201cYou have ran out of pocket money\u201d)<\/em><\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"650\"><strong>Pre-defined functions<\/strong> (with parameters) \u2013<strong> <em>round(22.34 )<\/em><\/strong> will round numbers 22.34 becomes 22 or <strong><em>sqrt(4)<\/em><\/strong> will get the square root 2, or 9 will become 3.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Expressions to assign values to variables Number=0 Expressions to return values using arithmetic operations (+ &#8211; * \/ ^ mod) Average=total\/5 Execution of lines of code in sequence demonstrating input \u2013 process- output 1. SEND \u201cEnter First Number\u201d TO DISPLAY 2. RECEIVE first_number FROM (INTEGER) KEYBOARD [input] 3. SEND \u201cEnter Second Number\u201d TO DISPLAY 4. &hellip;<\/p>\n","protected":false},"author":32,"featured_media":1077,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17932,17013,17009],"tags":[],"class_list":["post-1109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computational-constructs","category-national-5","category-software-design-devlopment"],"jetpack_featured_media_url":"https:\/\/blogs.glowscotland.org.uk\/nl\/public\/ColtnessHS-ComputingScience\/uploads\/sites\/12638\/2016\/03\/Nat5.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/1109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/comments?post=1109"}],"version-history":[{"count":5,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/1109\/revisions"}],"predecessor-version":[{"id":1123,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/1109\/revisions\/1123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media\/1077"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media?parent=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/categories?post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/tags?post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}