{"id":2076,"date":"2024-03-16T19:13:51","date_gmt":"2024-03-16T19:13:51","guid":{"rendered":"https:\/\/www.tutavo.com\/Kachina\/?p=2076"},"modified":"2024-05-19T22:39:12","modified_gmt":"2024-05-19T22:39:12","slug":"learn-python-notes-61-70","status":"publish","type":"post","link":"https:\/\/www.tutavo.com\/Kachina\/learn-python-notes-61-70\/","title":{"rendered":"Learn Python \u2013 NOTES 61 \u2013 70"},"content":{"rendered":"<p><strong>Program 61 &#8211; Exchanging Values<\/strong><\/p>\n<pre>variable_1 = 1\r\nvariable_2 = 2\r\nvariable_1, variable_2 = variable_2, variable_1\r\n<\/pre>\n<p>OR<\/p>\n<p>variable_1 = &#8220;Good&#8221;<br \/>\nvariable_2 = &#8220;job&#8221;<br \/>\nvariable_1, variable_2 = variable_2, variable_1<br \/>\nprint(variable_1,variable_2)<br \/>\nvariable_1, variable_2 = variable_2, variable_1<br \/>\nprint(variable_1,variable_2)<\/p>\n<p>FOR LONG LISTS<\/p>\n<p>my_list = [10, 1, 8, 3, 5, 7, 34, 4, 76]<br \/>\nlength = len(my_list)<br \/>\nfor i in range(length \/\/ 2):<br \/>\nmy_list[i], my_list[length &#8211; i &#8211; 1] = my_list[length &#8211; i &#8211; 1], my_list[i]<br \/>\nprint(my_list)<\/p>\n<p>length = len(my_list)<br \/>\nfor i in range(length \/\/ 2):<br \/>\nmy_list[i], my_list[length &#8211; i &#8211; 1] = my_list[length &#8211; i &#8211; 1], my_list[i]<br \/>\nprint(my_list)<\/p>\n<p><strong>Program 62 &#8211; Finding a Value in a List<\/strong><\/p>\n<pre>Now let's find the location of a given element inside a list:\r\nmy_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\nto_find = 5\r\nfound = False\r\nfor i in range(len(my_list)):\r\n    found = my_list[i] == to_find\r\n    if found:\r\n        break\r\nif found:\r\n    print(\"Element found at index\", i)\r\nelse:\r\n    print(\"absent\")\r\n\r\n<\/pre>\n<p><strong>Program 63 -Is this number prime?<br \/>\n<\/strong><\/p>\n<p>def is_prime(num):<br \/>\nif num &lt; 2:<br \/>\nreturn False<br \/>\nfor i in range(2, int(num ** 0.5) + 1):<br \/>\nif num % i == 0:<br \/>\nreturn False<br \/>\nreturn True<\/p>\n<p>for i in range(1, 61):<br \/>\nif is_prime(i):<br \/>\nprint(i)<\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 64 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 65 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 66 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 67 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 68 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 69 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n<p><strong>Program 70 &#8211; <\/strong><\/p>\n<pre>&nbsp;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Program 61 &#8211; Exchanging Values variable_1 = 1 variable_2 = 2 variable_1, variable_2 = variable_2, variable_1 OR variable_1 = &#8220;Good&#8221; variable_2 = &#8220;job&#8221; variable_1, variable_2 = variable_2, variable_1 print(variable_1,variable_2) variable_1, variable_2 = variable_2, variable_1 print(variable_1,variable_2) FOR LONG LISTS my_list = [10, 1, 8, 3, 5, 7, 34, 4, 76] length = len(my_list) for i in &hellip; <a href=\"https:\/\/www.tutavo.com\/Kachina\/learn-python-notes-61-70\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learn Python \u2013 NOTES 61 \u2013 70&#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-2076","post","type-post","status-publish","format-standard","hentry","category-educational"],"_links":{"self":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/2076","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=2076"}],"version-history":[{"count":7,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/2076\/revisions"}],"predecessor-version":[{"id":2108,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/posts\/2076\/revisions\/2108"}],"wp:attachment":[{"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/media?parent=2076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/categories?post=2076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutavo.com\/Kachina\/wp-json\/wp\/v2\/tags?post=2076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}