{"id":2043,"date":"2018-06-19T12:42:01","date_gmt":"2018-06-19T11:42:01","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/?p=2043"},"modified":"2018-06-19T12:43:11","modified_gmt":"2018-06-19T11:43:11","slug":"higher-input-validation-revision","status":"publish","type":"post","link":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/2018\/06\/19\/higher-input-validation-revision\/","title":{"rendered":"Higher &#8211; Input Validation (Revision)"},"content":{"rendered":"<p>We use the standard algorithm input validation to check that the user is entering a value that is expected by the program. In the example below our function is used to check that the entered integer is between a max and min value.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python; title: Input Validation; notranslate\" title=\"Input Validation\">\r\ndef getValidInt(fMin,fMax):\r\n    print(&quot;Please enter a number between&quot;,str(fMin), &quot;and&quot;,str(fMax))\r\n    number=int(input())\r\n    while number&lt;fMin or number&gt;fMax:\r\n        print(&quot;Sorry try again&quot;)\r\n        print(&quot;Please enter a number between&quot;,str(fMin), &quot;and&quot;,str(fMax))\r\n        number=int(input())\r\n\r\n    return number\r\n\r\ndef main():\r\n    min=-100\r\n    max=100\r\n    \r\n    number1=getValidInt(min,max)\r\n    number2=getValidInt(1,20)\r\n    print(number1,number2)\r\n\r\nmain()\r\n<\/pre>\n<p>The function follows the AREA standard algorithm, that is Ask Repeat Error Ask. so<\/p>\n<ol>\n<li><strong>Ask<\/strong> for valid number<\/li>\n<li><strong>Repeat<\/strong> While number not valid<\/li>\n<li>\u00a0 \u00a0 Display <strong>Error<\/strong><\/li>\n<li>\u00a0 \u00a0 <strong>Ask<\/strong> for valid number<\/li>\n<\/ol>\n<p>Too remember this mnemonic easier think Jonathan Ross for step 2, as in Python we would use a While.<\/p>\n<p>The code above makes use of local variables as well as formal and actual parameters. Can you spot them?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use the standard algorithm input validation to check that the user is entering a value that is expected by the program. In the example below our function is used to check that the entered integer is between a max and min value. &nbsp; def getValidInt(fMin,fMax): print(&quot;Please enter a number between&quot;,str(fMin), &quot;and&quot;,str(fMax)) number=int(input()) while number&lt;fMin &hellip;<\/p>\n","protected":false},"author":32,"featured_media":1386,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[432098,17932,432053,17009],"tags":[],"class_list":["post-2043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-higher","category-computational-constructs","category-national-5-2","category-software-design-devlopment"],"jetpack_featured_media_url":"https:\/\/blogs.glowscotland.org.uk\/nl\/public\/ColtnessHS-ComputingScience\/uploads\/sites\/12638\/2016\/09\/Slide4.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2043","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=2043"}],"version-history":[{"count":4,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2043\/revisions"}],"predecessor-version":[{"id":2047,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/2043\/revisions\/2047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media\/1386"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media?parent=2043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/categories?post=2043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/tags?post=2043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}