{"id":70,"date":"2020-05-10T19:06:39","date_gmt":"2020-05-10T23:06:39","guid":{"rendered":"https:\/\/blog.lemonthy.com\/?p=70"},"modified":"2020-05-28T15:59:58","modified_gmt":"2020-05-28T19:59:58","slug":"happy-mothers-day","status":"publish","type":"post","link":"https:\/\/blog.lemonthy.com\/?p=70","title":{"rendered":"Python Program Happy Mother&#8217;s Day"},"content":{"rendered":"\n<p>Happy Mother&#8217;s Day to all Mom<\/p>\n\n\n\n<p>Here is a the python way of saying &#8220;Happy Mother&#8217;s Day&#8221; <\/p>\n\n\n\n<p>Let&#8217;s put these code in pycharm and run it for Mom.<\/p>\n\n\n\n<p>first one can run on trinket.io<\/p>\n\n\n\n<p>motherday1.py<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(<strong>'\\n'<\/strong>.join([<strong>''<\/strong>.join([(<strong>'Love'<\/strong>[(x-y) % len(<strong>'Love'<\/strong>)] <strong>if <\/strong>((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 &lt;= 0 <strong>else ' '<\/strong>) <strong>for <\/strong>x <strong>in <\/strong>range(-30, 30)]) <strong>for <\/strong>y <strong>in <\/strong>range(12, -10, -1)]))<\/pre>\n\n\n\n<p>result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>            veLoveLov           veLoveLov               \n        eLoveLoveLoveLove   eLoveLoveLoveLove           \n      veLoveLoveLoveLoveLoveLoveLoveLoveLoveLov         \n     veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL        \n    veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLov       \n    eLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove       \n    LoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL       \n    oveLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLo       \n    veLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLov       \n    eLoveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove       \n     oveLoveLoveLoveLoveLoveLoveLoveLoveLoveLove        \n      eLoveLoveLoveLoveLoveLoveLoveLoveLoveLove         \n      LoveLoveLoveLoveLoveLoveLoveLoveLoveLoveL         \n        eLoveLoveLoveLoveLoveLoveLoveLoveLove           \n         oveLoveLoveLoveLoveLoveLoveLoveLove            \n          eLoveLoveLoveLoveLoveLoveLoveLove             \n            veLoveLoveLoveLoveLoveLoveLov               \n              oveLoveLoveLoveLoveLoveLo                 \n                LoveLoveLoveLoveLoveL                   \n                   LoveLoveLoveLov                      \n                      LoveLoveL                         \n                         Lov                            <\/code><\/pre>\n\n\n\n<p>Then, we need add some color for this heart. Since we are import modouls, following program can only run in pycharm. If you want to know how to download pycharm, please check on this link <a href=\"https:\/\/blog.lemonthy.com\/?p=52\">Python environment guide [Pycharm IDE]<\/a> .<\/p>\n\n\n\n<p>motherday2.py<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>import <\/strong>colorama<br>RED = colorama.Fore.RED + colorama.Style.BRIGHT<br>print(RED+<strong>'<\/strong><strong>\\n<\/strong><strong>'<\/strong>.join([<strong>''<\/strong>.join([(<strong>'Love'<\/strong>[(x-y) % len(<strong>'Love'<\/strong>)] <strong>if <\/strong>((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 &lt;= 0 <strong>else <\/strong><strong>' '<\/strong>) <strong>for <\/strong>x <strong>in <\/strong>range(-30, 30)]) <strong>for <\/strong>y <strong>in <\/strong>range(12, -10, -1)]))<\/pre>\n\n\n\n<p>If you receive error on missing module colorama, you know there are 2 ways to install this module as we tought in class. one way is : pip3 install colorama<\/p>\n\n\n\n<p>Next, add more colors , flowers, sleep delay, random space in left, and loops with dynamic colorful result<\/p>\n\n\n\n<p>motherday3.py<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>import <\/strong>colorama<br><strong>import <\/strong>time<br><strong>from <\/strong>random <strong>import <\/strong>*<br><br>RED = colorama.Fore.RED + colorama.Style.BRIGHT<br>CYAN = colorama.Fore.CYAN + colorama.Style.BRIGHT<br>GREEN = colorama.Fore.GREEN + colorama.Style.BRIGHT<br>YELLOW = colorama.Fore.YELLOW + colorama.Style.BRIGHT<br>MAGENTA = colorama.Fore.MAGENTA + colorama.Style.BRIGHT<br><br><em># Print header<br><\/em><strong>for <\/strong>i <strong>in <\/strong>range(1, 35):<br>    print(<strong>''<\/strong>)<br><em># *s position<br><\/em>heartStars = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76]<br><em># Position of space<br><\/em>heartBreakLines = [13, 27, 41, 55, 69, 77]<br><em># Empty column position of rose<br><\/em>flowerBreakLines = [7, 15, 23, 31, 39, 46]<br><br><em># add new column<br><\/em><strong>def <\/strong>addSpaces(a):<br>    count = a<br>    <strong>while <\/strong>count &gt; 0:<br>        print(<strong>' '<\/strong>, end=<strong>''<\/strong>)<br>        count -= 1<br><br><em># add new line<br><\/em><strong>def <\/strong>newLineWithSleep():<br>    time.sleep(0.3)<br>    print(<strong>'<\/strong><strong>\\n<\/strong><strong>'<\/strong>, end=<strong>''<\/strong>)<br><br>play = 0<br><strong>while <\/strong>play == 0:<br>    Left_Spaces = randint(8, 80)<br>    addSpaces(Left_Spaces)<br>    <em># draw heart<br><\/em><em>    <\/em><strong>for <\/strong>i <strong>in <\/strong>range(0, 78):<br>        <strong>if <\/strong>i <strong>in <\/strong>heartBreakLines:<br>            newLineWithSleep()<br>            addSpaces(Left_Spaces)<br>        <strong>elif <\/strong>i <strong>in <\/strong>heartStars:<br>            print(RED + <strong>'*'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(32, 36):<br>            print(GREEN + <strong>'M'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i == 34:<br>            print(GREEN + <strong>'O'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>else<\/strong>:<br>            print(<strong>' '<\/strong>, end=<strong>''<\/strong>)<br>    newLineWithSleep()<br>    addSpaces(randint(8, 80))<br>    print(CYAN + <strong>\"H a p p y  M o t h e r ' s   D a y !\"<\/strong>, end=<strong>''<\/strong>)<br>    newLineWithSleep()<br>    newLineWithSleep()<br>    Left_Spaces = randint(8, 80)<br>    addSpaces(Left_Spaces)<br>    <em># draw flower<br><\/em><em>    <\/em><strong>for <\/strong>i <strong>in <\/strong>range(0, 47):<br>        <strong>if <\/strong>i <strong>in <\/strong>flowerBreakLines:<br>            newLineWithSleep()<br>            addSpaces(Left_Spaces)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(2, 8, 12, 18):<br>            print(MAGENTA + <strong>'{'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(3, 9, 13, 19):<br>            print(MAGENTA + <strong>'_'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(4, 10, 14, 20):<br>            print(MAGENTA + <strong>'}'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(27, 35, 43):<br>            print(GREEN + <strong>'|'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i <strong>in <\/strong>(34, 44):<br>            print(GREEN + <strong>'~'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>elif <\/strong>i == 11:<br>            print(YELLOW + <strong>'o'<\/strong>, end=<strong>''<\/strong>)<br>        <strong>else<\/strong>:<br>            print(<strong>' '<\/strong>, end=<strong>''<\/strong>)<br>    print(<strong>'<\/strong><strong>\\n<\/strong><strong>'<\/strong>, end=<strong>''<\/strong>)<\/pre>\n\n\n\n<p>result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"662\" src=\"https:\/\/blog.lemonthy.com\/wp-content\/uploads\/2020\/05\/image-1024x662.png\" alt=\"\" class=\"wp-image-71\" srcset=\"https:\/\/blog.lemonthy.com\/wp-content\/uploads\/2020\/05\/image-1024x662.png 1024w, https:\/\/blog.lemonthy.com\/wp-content\/uploads\/2020\/05\/image-300x194.png 300w, https:\/\/blog.lemonthy.com\/wp-content\/uploads\/2020\/05\/image-768x496.png 768w, https:\/\/blog.lemonthy.com\/wp-content\/uploads\/2020\/05\/image.png 1241w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Happy Mother&#8217;s Day to all Mom Here is a the python way of saying &#8220;Happy Mother&#8217;s Day&#8221; Let&#8217;s put these code in pycharm and run it for Mom. first one can run on trinket.io motherday1.py print(&#8216;\\n&#8217;.join([&#8221;.join([(&#8216;Love'[(x-y) % len(&#8216;Love&#8217;)] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 &lt;= 0 else &#8216; &#8216;) for x in range(-30, 30)]) for y in range(12, -10, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.lemonthy.com\/?p=70\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Python Program Happy Mother&#8217;s Day&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":9,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lemonthy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}