{"id":964,"date":"2015-11-30T15:14:57","date_gmt":"2015-11-30T15:14:57","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/?p=964"},"modified":"2015-11-30T15:14:57","modified_gmt":"2015-11-30T15:14:57","slug":"n5-higher-input-validation-python","status":"publish","type":"post","link":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/2015\/11\/30\/n5-higher-input-validation-python\/","title":{"rendered":"N5 &amp; Higher &#8211; Input Validation (Python)"},"content":{"rendered":"<p><!-- HTML generated using hilite.me -->Input validation is used in both National 5 and at Higher. It consists of 3 parts.<\/p>\n<ol>\n<li>Get the user to enter a value<\/li>\n<li>While the value is wrong<\/li>\n<li>\u00a0 \u00a0 Get the user to enter a value<\/li>\n<\/ol>\n<p>The use of the while\u00a0construct allows the program to repeatedly ask the user to enter valid data.<\/p>\n<div style=\"background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\">1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\">age<span style=\"color: #333333\">=<\/span><span style=\"color: #0000dd;font-weight: bold\">0<\/span>\r\n\r\n<span style=\"color: #888888\">#Input Validation<\/span>\r\nage<span style=\"color: #333333\">=<\/span><span style=\"color: #007020\">int<\/span>(<span style=\"color: #007020\">input<\/span>(<span style=\"background-color: #fff0f0\">'Please enter your age&gt;'<\/span>))\r\n<span style=\"color: #008800;font-weight: bold\">while<\/span> age<span style=\"color: #333333\">&lt;<\/span><span style=\"color: #0000dd;font-weight: bold\">0<\/span> <span style=\"color: #000000;font-weight: bold\">or<\/span> age<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #0000dd;font-weight: bold\">120<\/span>: <span style=\"color: #888888\"># Check that age is between 0 and 120<\/span>\r\n    <span style=\"color: #008800;font-weight: bold\">print<\/span>(<span style=\"background-color: #fff0f0\">'Please check your age is between 0 and 120'<\/span>)\r\n    age<span style=\"color: #333333\">=<\/span><span style=\"color: #007020\">int<\/span>(<span style=\"color: #007020\">input<\/span>(<span style=\"background-color: #fff0f0\">'Please enter your age&gt;'<\/span>))\r\n    \r\n<span style=\"color: #008800;font-weight: bold\">print<\/span>(<span style=\"background-color: #fff0f0\">'Welcome'<\/span>)\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>This can also be used with strings, can you work out how to modify the code so that it would only take a &#8216;Yes&#8217; &#8216;No&#8217; answer?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Input validation is used in both National 5 and at Higher. It consists of 3 parts. Get the user to enter a value While the value is wrong \u00a0 \u00a0 Get the user to enter a value The use of the while\u00a0construct allows the program to repeatedly ask the user to enter valid data. 1 &hellip;<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17935,17009],"tags":[18069,125715],"class_list":["post-964","post","type-post","status-publish","format-standard","hentry","category-algorithm-specification","category-software-design-devlopment","tag-input-validation","tag-python"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/964","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=964"}],"version-history":[{"count":2,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/964\/revisions"}],"predecessor-version":[{"id":966,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/posts\/964\/revisions\/966"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/media?parent=964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/categories?post=964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/nl\/ColtnessHS-ComputingScience\/wp-json\/wp\/v2\/tags?post=964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}