{"id":1300,"date":"2024-12-27T14:54:41","date_gmt":"2024-12-27T13:54:41","guid":{"rendered":"https:\/\/vroamam.com\/wordpress\/?p=1300"},"modified":"2024-12-27T14:54:41","modified_gmt":"2024-12-27T13:54:41","slug":"day-3-control-flow-and-logical-operators","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/day-3-control-flow-and-logical-operators\/","title":{"rendered":"Day 3 &#8211; Control Flow and Logical Operators"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Day 3 Goals<\/li>\n\n\n\n<li>if\/else statements<\/li>\n\n\n\n<li>Modulo<\/li>\n\n\n\n<li>Nested if\/else and elif statements<\/li>\n\n\n\n<li>Coding Exercise: BMI Calculator Version 2<\/li>\n\n\n\n<li>Multiple if statements<\/li>\n\n\n\n<li>Coding Practice: Pizza Order<\/li>\n\n\n\n<li>Logical Operators<\/li>\n\n\n\n<li>Project: Treasure Island<\/li>\n<\/ul>\n\n\n\n<p>My BMI Calculator V2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>weight = 70\nheight = 1.85\n\nbmi = weight \/ (height ** 2)\nprint(bmi)\n\nif bmi &lt; 18.5:\n    print(\"Underweight\")\nelif bmi &lt; 25:\n    print(\"Normal Weight\")\nelse:\n    print(\"Overweight\")\n\n# I note that in Angela's example she has the if\/elif\/else the opposite way around.\n# I have not found any errata in my code, the weights appear to be identified correctly \n# if bmi &gt;= 25:\n#    print(\"overweight\")\n# elif bmi &gt;= 18.5:\n#    print(\"normal weight\")\n# else:\n#    print(\"Overweight\")<\/code><\/pre>\n\n\n\n<p>My pizza order<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"Welcome to Python Pizza Deliveries!\")\nsize = input(\"What size pizza do you want? S, M or L: \").lower()\npepperoni = input(\"Do you want pepperoni on your pizza? Y or N: \").lower()\nextra_cheese = input(\"Do you want extra cheese? Y or N: \").lower()\ncost = 0\n\n# Calculate the base cost\nif size == \"s\":\n    cost += 15\nelif size == \"m\":\n    cost += 20\nelse:\n    cost += 25\n\n# Calculate the cost of the pepperoni\nif pepperoni == \"y\":\n    if size == \"s\":\n        cost += 2\n    else:\n        cost += 3\n\n# Calculate the cost of the extra cheese\nif extra_cheese == \"y\":\n    cost += 1\n\n# Print the bill\nif size == \"s\":\n    print(\"\\nyou ordered a small pizza $15 with the following toppings\")\n    if pepperoni == \"y\":\n        print(\"Pepperoni + $2\")\n    else:\n        print(\"No pepperoni\")\n    if extra_cheese == \"y\":\n        print(\"Extra cheese + $1\")\n\nif size == \"m\":\n    print(\"\\nyou ordered a medium pizza with the following toppings\")\n    if pepperoni == \"y\":\n        print(\"Pepperoni + $3\")\n    else:\n        print(\"No pepperoni\")\n    if extra_cheese == \"y\":\n        print(\"Extra cheese +$1\")\n    else:\n        print(\"No extra cheese\")\n\nif size == \"l\":\n    print(\"\\nyou ordered a large pizza with the following toppings\")\n    if pepperoni == \"y\":\n       print(\"Pepperoni + $3\")\n    else:\n       print(\"No pepperoni\")\n    if extra_cheese == \"y\":\n       print(\"Extra cheese +$1\")\n    else:\n       print(\"No extra cheese\")\n\nprint(f\"\\nYour final bill is: ${cost}.\")<\/code><\/pre>\n\n\n\n<p>My Treasure Island game<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(r'''<br>*******************************************************************************<br>          |                   |                  |                     |<br> _________|________________.=\"\"_;=.______________|_____________________|_______<br>|                   |  ,-\"_,=\"\"     `\"=.|                  |<br>|___________________|__\"=._o`\"-._        `\"=.______________|___________________<br>          |                `\"=._o`\"=._      _`\"=._                     |<br> _________|_____________________:=._o \"=._.\"_.-=\"'\"=.__________________|_______<br>|                   |    __.--\" , ; `\"=._o.\" ,-\"\"\"-._ \".   |<br>|___________________|_._\"  ,. .` ` `` ,  `\"-._\"-._   \". '__|___________________<br>          |           |o`\"=._` , \"` `; .\". ,  \"-._\"-._; ;              |<br> _________|___________| ;`-.o`\"=._; .\" ` '`.\"\\ ` . \"-._ \/_______________|_______<br>|                   | |o ;    `\"-.o`\"=._``  '` \" ,__.--o;   |<br>|___________________|_| ;     (#) `-.o `\"=.`_.--\"_o.-; ;___|___________________<br>____\/______\/______\/___|o;._    \"      `\".o|o_.--\"    ;o;____\/______\/______\/____<br>\/______\/______\/______\/_\"=._o--._        ; | ;        ; ;\/______\/______\/______\/_<br>____\/______\/______\/______\/__\"=._o--._   ;o|o;     _._;o;____\/______\/______\/____<br>\/______\/______\/______\/______\/____\"=._o._; | ;_.--\"o.--\"_\/______\/______\/______\/_<br>____\/______\/______\/______\/______\/_____\"=.o|o_.--\"\"___\/______\/______\/______\/____<br>\/______\/______\/______\/______\/______\/______\/______\/______\/______\/______\/_____ \/<br>*******************************************************************************<br>''')<br>print(\"Welcome to Treasure Island.\")<br>print(\"Your mission is to find the treasure.\")<br><br>choice = input('you are at a crossroads which way do you go (L) left or (R) right').lower()<br>if choice == 'l':<br>    choice2 = input(\"well done! you arrived at a lake. Would you like to (S) swim or (W) wait\").lower()<br>    if choice2 == 'w':<br>        choice3 = input(\"You arrive at a house with 3 doors.\"<br>                        \"One red, one yellow and one blue. Which colour do you choose - type the colour?\").lower()<br>        if choice3 == 'red':<br>            print(\"It's a room full of fire. Game Over\")<br>        elif choice3 == 'yellow':<br>            print(\"You found the treasure. You Win!\")<br>        elif choice3 == 'blue':<br>            print(\"You enter a room of beasts. Game Over.\")<br>        else:<br>            print(\"You chose a door that doesn't exist. Game Over.\")<br>    else:<br>        print(\"you are attacked by a trout. Game Over\")<br>elif choice == 'r':<br>    print(\"You made the wrong choice turning right - Game Over\")<br>else:<br>    print(\"Your inability to follow instructions means you met a horrible death at the hands of the barbarian army\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My BMI Calculator V2 My pizza order My Treasure Island game print(r&#8221;&#8217;******************************************************************************* | | | | _________|________________.=&#8221;&#8221;_;=.______________|_____________________|_______| | ,-&#8220;_,=&#8221;&#8221; `&#8221;=.| ||___________________|__&#8221;=._o`&#8221;-._ `&#8221;=.______________|___________________ | `&#8221;=._o`&#8221;=._ _`&#8221;=._ | _________|_____________________:=._o &#8220;=._.&#8221;_.-=&#8221;&#8216;&#8221;=.__________________|_______| | __.&#8211;&#8221; , ; `&#8221;=._o.&#8221; ,-&#8220;&#8221;&#8221;-._ &#8220;. ||___________________|_._&#8221; ,. .` ` &#8220; , `&#8221;-._&#8221;-._ &#8220;. &#8216;__|___________________ | |o`&#8221;=._` , &#8220;` `; .&#8221;. , &#8220;-._&#8221;-._; ; | _________|___________| [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[144,148,3],"tags":[146,145,11],"class_list":["post-1300","post","type-post","status-publish","format-standard","hentry","category-100daysofcode","category-python","category-training","tag-100daysofcode","tag-python","tag-training","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pahuGk-kY","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1300"}],"version-history":[{"count":4,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1306,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1300\/revisions\/1306"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}