{"id":1972,"date":"2024-01-26T20:21:50","date_gmt":"2024-01-26T20:21:50","guid":{"rendered":"https:\/\/www.tutavo.com\/Kachina\/?p=1972"},"modified":"2024-01-29T18:20:03","modified_gmt":"2024-01-29T18:20:03","slug":"learn-python-notes-11-20","status":"publish","type":"post","link":"https:\/\/www.tutavo.com\/Kachina\/learn-python-notes-11-20\/","title":{"rendered":"Learn Python &#8211; NOTES 11 &#8211; 20"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 11 &#8211; Simple Math with Variables<br \/>\n<\/strong><\/p>\n<p>john=3<br \/>\nmary=5<br \/>\nadam=6<br \/>\nprint(john,mary,adam,sep=&#8221;, &#8220;)<br \/>\ntotal_apples=john+mary+adam<br \/>\nprint (&#8220;Total Apples; &#8220;, total_apples)<\/p>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 12 &#8211; Simple DO WHILE<br \/>\n<\/strong><\/p>\n<p>sheep=1<br \/>\nwhile sheep&lt;=20:<br \/>\nprint (sheep)<br \/>\nsheep = sheep + 1<br \/>\n# END<\/p>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 13 &#8211; Shortcut Operators<br \/>\n<\/strong><\/p>\n<ul>\n<li>print (i = i + 2 * j &nbsp; &nbsp;&nbsp; \u21d2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i += 2 * j)<\/li>\n<li>print (var = var \/ 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u21d2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var \/= 2)<\/li>\n<li>print (rem = rem % 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u21d2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rem %= 10)<\/li>\n<li>print (j = j &#8211; (i + var + rem)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u21d2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j -= (i + var + rem))<\/li>\n<li>print (x = x ** 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u21d2 &nbsp; &nbsp;&nbsp; x **= 2)<\/li>\n<\/ul>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 14 &#8211; Input Data from keyboard<br \/>\n<\/strong><\/p>\n<p>print(&#8220;Tell me anything&#8230;&#8221;)<br \/>\nanything = input()<br \/>\nprint(&#8220;Hmm&#8230;&#8221;, anything, &#8220;&#8230; Really?&#8221;)<\/p>\n<p>or<\/p>\n<p>anything = input(&#8220;Tell me anything&#8230;&#8221;)<br \/>\nprint(&#8220;Hmm&#8230;&#8221;, anything, &#8220;&#8230;Really?&#8221;)<\/p>\n<p>THIS IS A TEXT STRING<\/p>\n<p><code class=\"codep \">anything = input(\"Enter a number: \")<\/code><\/p>\n<p><code class=\"codep \">something = anything ** 2.0<br \/>\nprint<br \/>\n(anything, \"to the power of 2 is\", something)<\/code><\/p>\n<p>MUST BE CODED LIKE THIS<\/p>\n<p><code class=\"codep \">anything = input(\"Enter a number: \")<\/code><\/p>\n<p><code class=\"codep \">something = anything ** 2.0<br \/>\nprint<br \/>\n<\/code><code class=\"codep \">(anything, \"to the power of 2 is\", something)<\/code><\/p>\n<p>OR<\/p>\n<p>anything = float(input(&#8220;Enter a number: &#8220;))<\/p>\n<p><strong># Sample Python Program 15 &#8211; Input of Strings<\/strong><\/p>\n<p>fnam = input(&#8220;May I have your first name, please? &#8220;)<br \/>\nlnam = input(&#8220;May I have your last name, please? &#8220;)<br \/>\nprint(&#8220;Thank you.&#8221;)<br \/>\nprint(&#8220;\\nYour name is &#8221; + fnam + &#8221; &#8221; + lnam + &#8220;.&#8221;)<\/p>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 16 &#8211; Repetition of a String<br \/>\n<\/strong><\/p>\n<p><code class=\"codep syntax-color\"><span class=\"ace_identifier\">print (string<\/span> <span class=\"ace_keyword ace_operator\">*<\/span> <span class=\"ace_identifier\">number)<\/span><\/code><\/p>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 17 &#8211; Order of Operations<br \/>\n<\/strong><\/p>\n<p><strong>priority table<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<th>Priority<\/th>\n<th>Operator<\/th>\n<th>&nbsp;<\/th>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td><code>+<\/code>, <code>-<\/code><\/td>\n<td>unary<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><code>**<\/code><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><code>*<\/code>, <code>\/<\/code>, <code>\/\/<\/code>, <code>%<\/code><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><code>+<\/code>, <code>-<\/code><\/td>\n<td>binary<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><code>&lt;<\/code>, <code>&lt;=<\/code>, <code>&gt;<\/code>, <code>&gt;=<\/code><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><code>==<\/code>, <code>!=<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><code class=\"codep syntax-color\"><\/code># Sample Python Program 18 &#8211; IF \/ ELSE \/ ELIF<br \/>\n<\/strong><\/p>\n<p>if x=0:<br \/>\n&nbsp;&nbsp;&nbsp; do this<br \/>\nelse: # This is done with a single possible outcome<br \/>\n&nbsp;&nbsp;&nbsp; do this<br \/>\nelif:&nbsp; # This replaces the Select Case conditional<br \/>\n&nbsp;&nbsp;&nbsp; do this or several other Elifs &#8211; Exits after first positive<br \/>\nelse:<\/p>\n<p>Shortcut<\/p>\n<p>If x=0: do this<br \/>\nElse: do this instead<\/p>\n<p><strong>&nbsp;# Sample Python Program 19 &#8211; Example Code<br \/>\n<\/strong><\/p>\n<p>x = input(&#8220;Enter dog&#8217;s name: &#8220;)<br \/>\nif x == &#8220;Jasmine&#8221;:dog_name=&#8221;Horray for Jasmine&#8221;<br \/>\nelif x == &#8220;jasmine&#8221;:dog_name=&#8221;I want an upper case Jasmine.&#8221;<br \/>\nelse: x=&#8221;This is not Jasmine.&#8221; # ALL OTHER CONDITIONS<\/p>\n<p>print(dog_name)<\/p>\n<p><strong>&nbsp;# Sample Python Program 20 &#8211; Thaler Tax Program<\/strong>#<br \/>\ncap = 85528<br \/>\ntarget_tax=14839.02<br \/>\ncurrency = &#8220;Thalers&#8221;<\/p>\n<p>income = float(input(&#8220;Enter income: &#8220;))<br \/>\nif income &gt;= cap:<br \/>\nprint(&#8220;Tax is due @ target_tax+32% of excess&#8221;)<br \/>\ndiff=(income-cap)<br \/>\nperc=(diff*.32)<br \/>\nprint(perc)<br \/>\ntax=(target_tax + perc)<br \/>\nelse:<br \/>\nprint(&#8220;Tax is due at 18% &#8211; 556.02&#8221;)<br \/>\nperc=(income*.18)<br \/>\ntax=(perc-556.02)<\/p>\n<p>tax = round(tax, 0)<br \/>\nif tax&lt;0: tax=0<br \/>\nprint(&#8220;The tax is:&#8221;, tax, currency)<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; # Sample Python Program 11 &#8211; Simple Math with Variables john=3 mary=5 adam=6 print(john,mary,adam,sep=&#8221;, &#8220;) total_apples=john+mary+adam print (&#8220;Total Apples; &#8220;, total_apples) # Sample Python Program 12 &#8211; Simple DO WHILE sheep=1 while sheep&lt;=20: print (sheep) sheep = sheep + 1 # END # Sample Python Program 13 &#8211; Shortcut Operators print (i = i &hellip; <a href=\"https:\/\/www.tutavo.com\/Kachina\/learn-python-notes-11-20\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learn Python &#8211; NOTES 11 &#8211; 20&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1972","post","type-post","status-publish","format-standard","hentry","category-educational"],"_links":{"self":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/1972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/comments?post=1972"}],"version-history":[{"count":14,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/1972\/revisions"}],"predecessor-version":[{"id":1990,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/1972\/revisions\/1990"}],"wp:attachment":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/media?parent=1972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/categories?post=1972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/tags?post=1972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}