{"id":228,"date":"2020-11-10T10:08:55","date_gmt":"2020-11-10T10:08:55","guid":{"rendered":"http:\/\/lamiaiftekhar.com\/?page_id=228"},"modified":"2020-11-10T10:08:55","modified_gmt":"2020-11-10T10:08:55","slug":"228-2","status":"publish","type":"page","link":"https:\/\/lamiaiftekhar.com\/index.php\/228-2\/","title":{"rendered":""},"content":{"rendered":"<body>\n<p>We continue loops today.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Previously we first defined a specific list first and then looped through the items in the list. We can actually define the list in the loop command itself.<\/li><\/ol>\n\n\n\n<p>Type and run<\/p>\n\n\n\n<p><strong>for number in [1,2,3]:<br>print(number, 5<em>number, 10<\/em>number)<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Type and run<\/li><\/ol>\n\n\n\n<p><strong>for area in [\u2018Tejgaon\u2019, \u2018Bashundhara\u2019, \u2018Shyamoli\u2019]:<br>print(area)<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>We can also use the \u2018range\u2019 concept to make a loop go through an ordered sequence of numbers (instead of explicitly defining, let\u2019s say list1=[1,2,3,4,5] )<\/li><\/ol>\n\n\n\n<p>Type and run<\/p>\n\n\n\n<p><strong>for number in range(5):<br>print(number, number*2)<\/strong><\/p>\n\n\n\n<p>4. Note that using range(5) gives you the numbers from 0 to 4. So using range(n) will give you the number from 0 to n-1. What if you want a number range starting from a different value other than zero?<\/p>\n\n\n\n<p><strong>for i in range(3,6):<br>print(i)<\/strong><\/p>\n\n\n\n<p>5. Note that range(n1, n2) gives you numbers starting from (including) n1 and ending at n2-1.<\/p>\n\n\n\n<p>Write a code that will print the numbers 1 to 5.<\/p>\n\n\n\n<p>5. We can even specify steps in range. The format is range(start, stop, step).<\/p>\n\n\n\n<p>Type and run<\/p>\n\n\n\n<p><strong>for item in range(1,10,2):<br>print(item)<\/strong><\/p>\n\n\n\n<p>6. In the above the program starts from the first number 1 and then hops 2 steps at every iteration until it reaches the end. We can also hop backwards!<\/p>\n\n\n\n<p><strong>for number in range(10, -10, -3):<br>print(number)<\/strong><\/p>\n\n\n\n<p>6. Print all the integers between (and including) 195 and 200 but backwards ( I.e., start from 200 and end at 195)<\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>We continue loops today. Previously we first defined a specific list first and then looped through the items in the list. We can actually define the list in the loop command itself. Type and run for number in [1,2,3]:print(number, 5number, 10number) Type and run for area in [\u2018Tejgaon\u2019, \u2018Bashundhara\u2019, \u2018Shyamoli\u2019]:print(area) We can also use the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-228","page","type-page","status-publish","hentry","entry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":1,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/228\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/228\/revisions\/229"}],"wp:attachment":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/media?parent=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}