{"id":213,"date":"2020-11-10T09:38:04","date_gmt":"2020-11-10T09:38:04","guid":{"rendered":"http:\/\/lamiaiftekhar.com\/?page_id=213"},"modified":"2020-11-10T09:38:04","modified_gmt":"2020-11-10T09:38:04","slug":"20-minutes-python-day-7","status":"publish","type":"page","link":"https:\/\/lamiaiftekhar.com\/index.php\/20-minutes-python-day-7\/","title":{"rendered":"20-Minutes Python: Day 7"},"content":{"rendered":"<body>\n<p>So, in the last session, we learned how to make integer,\u00a0 float and string variables.\u00a0<br><br>Today let us do some operations using integer and float variables!<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>Write and run<\/li><\/ol>\n\n\n\n<p><strong>a=2<\/strong><\/p>\n\n\n\n<p><strong>b=5<\/strong><\/p>\n\n\n\n<p><strong>print(a+b)<\/strong><\/p>\n\n\n\n<p><strong>print(b-a)<\/strong><\/p>\n\n\n\n<p><strong>product =a*b<\/strong><\/p>\n\n\n\n<p><strong>print(product)<\/strong><\/p>\n\n\n\n<p><strong>bhaag=b\/a<\/strong><\/p>\n\n\n\n<p><strong>ultaBhaag=a\/b<\/strong><\/p>\n\n\n\n<p><strong>print(bhaag,ultaBhaag)<\/strong><\/p>\n\n\n\n<p>Which of the printouts are integers?\u00a0 Which become floats? Python will leave the results of operations between integers\u00a0 as integers,\u00a0 unless they are forced to show a decimal value \ud83d\ude00<\/p>\n\n\n\n<p>2. Now write and run<\/p>\n\n\n\n<p><strong>a = 2<\/strong><\/p>\n\n\n\n<p><strong>b = 1.0<\/strong><\/p>\n\n\n\n<p><strong>print(a*b)<\/strong><\/p>\n\n\n\n<p>What is the type of output?\u00a0 If any of the original variables is a float \u2013 the result will also be a float.<\/p>\n\n\n\n<p>3. We can also define variables simultaneously as follows:<\/p>\n\n\n\n<p><strong>a,b,c =3,0,1<\/strong><\/p>\n\n\n\n<p><strong>print(c)<\/strong><\/p>\n\n\n\n<p><strong>print(a+b, a-c)<\/strong><\/p>\n\n\n\n<p>4. \u2018%\u2019 is a modulo operation in math.\u00a0 It gives you the \u2018remainder\u2019 after a division.\u00a0<\/p>\n\n\n\n<p>For example,\u00a0\u00a0 5 \/2 ( 5 divided by 2) is\u00a0 2.5, right?\u00a0\u00a0 Then 5%2 would be 1\u00a0 ( If you divide 5 by 2, you can go 2 times\u00a0 to get 4\u00a0 and then \u20181\u2019 is remaining).<\/p>\n\n\n\n<p>Write the following and print them. (Try predicting the answers in your head first).<\/p>\n\n\n\n<p><strong>Leftover =\u00a0 7%c\u00a0\u00a0\u00a0<\/strong><\/p>\n\n\n\n<p><strong>Leftover2 = 3%2<\/strong><\/p>\n\n\n\n<p>Your \u2018c\u2019 was previously defined in the preceding cell most likely.\u00a0<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>5. Power operation is **<\/p>\n\n\n\n<p><br>Write the following and run<\/p>\n\n\n\n<p><strong>Number = 4<\/strong><\/p>\n\n\n\n<p><strong>NumberSquared = Number**2<\/strong><\/p>\n\n\n\n<p><strong>NumberCubed = Number**3<\/strong><\/p>\n\n\n\n<p><strong>NumberSquareRooted = Number**(0.5)<\/strong><\/p>\n\n\n\n<p><strong>print(NumberSquared, NumberCubed, NumberSquareRooted)<\/strong><\/p>\n\n\n\n<p><strong>Exercise:<\/strong><\/p>\n\n\n\n<p>The number 1729 is a very interesting number.\u00a0\u00a0 It is called the taxicab number or Hardy-Ramanujan number based on an interesting story (Google 1729 and keep the Wikipedia entry handy for this exercise.\u00a0 There is also a nice movie based on those two mathematicians \u2013 especially the young Indian genius \u2013 Ramanujan.).<\/p>\n\n\n\n<p>A. <strong>Define four variables a,b,c and d<\/strong>\u00a0 such that\u00a0\u00a0<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The additions of the cubes of a and b\u00a0 result in 1729<\/li><li>The additions of the cubes of c and d also result in 1729\u00a0<\/li><\/ul>\n\n\n\n<p>[ Hint:\u00a0 Third paragraph of that Wikipedia entry \/\u00a0 the first equation of that Wikipedia entry ]<\/p>\n\n\n\n<p><strong>Cube them pairwise and print the results<\/strong>\u00a0 (1729 will be printed in both times).<\/p>\n\n\n\n<p>B. Now,\u00a0 <strong>\u00a0define three variable p1,p2 and p3<\/strong>\u00a0 which are the factors of this number 1729\u00a0 (factors of a number \u2018x\u2019\u00a0 are prime numbers which multiplied together gives the number \u2018x\u2019) [Hint: on the right box of the Wikipedia entry ]<\/p>\n\n\n\n<p><strong>Print out the product of these variables.\u00a0<\/strong><\/p>\n\n\n\n<p>C. Now,<\/p>\n\n\n\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Add the\u00a0 four digits in the number 1729<\/strong>\u00a0 (9,7, 2 and 1 ) and save the\u00a0 addition\u00a0 in\u00a0 variable called \u2018Masahiko\u2019.<\/p>\n\n\n\n<p><strong>Invert the order of the digits in \u2018Masahiko\u2019 and save the new number as \u2018Fujiwara\u2019<\/strong>\u00a0 (Both Masahiko and Fujiwara will be numbers that are less than 100).<\/p>\n\n\n\n<p><strong>Now multiply Masahiko with Fujiwara<\/strong> and print out the result!<\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>So, in the last session, we learned how to make integer,\u00a0 float and string variables.\u00a0 Today let us do some operations using integer and float variables! Write and run a=2 b=5 print(a+b) print(b-a) product =a*b print(product) bhaag=b\/a ultaBhaag=a\/b print(bhaag,ultaBhaag) Which of the printouts are integers?\u00a0 Which become floats? Python will leave the results of operations [&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-213","page","type-page","status-publish","hentry","entry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/213","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=213"}],"version-history":[{"count":1,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/213\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/pages\/213\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/lamiaiftekhar.com\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}