{"id":1361,"date":"2025-01-01T13:03:43","date_gmt":"2025-01-01T12:03:43","guid":{"rendered":"https:\/\/vroamam.com\/wordpress\/?p=1361"},"modified":"2025-01-01T13:03:43","modified_gmt":"2025-01-01T12:03:43","slug":"day-10-functions-with-outputs","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/day-10-functions-with-outputs\/","title":{"rendered":"Day 10 &#8211; Functions with Outputs"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Day 10 Goals<\/li>\n\n\n\n<li>Functions with Outputs (return)<\/li>\n\n\n\n<li>Multiple return values<\/li>\n\n\n\n<li>Coding Exercise: leap year<\/li>\n\n\n\n<li>Docstrings<\/li>\n\n\n\n<li>Project: Calculator<\/li>\n<\/ul>\n\n\n\n<p>Coding Exercise:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def is_leap_year(year):\n    leap_year = True\n    if year % 4 == 0:\n        if year % 100 == 0:\n            if year % 400 == 0:\n                leap_year = True\n                return leap_year\n            else:\n                leap_year = False\n                return leap_year\n        else:\n            leap_year = False\n            return leap_year\n    else:\n        leap_year = False\n    return leap_year\n\n\nprint(is_leap_year(1989))\n<\/code><\/pre>\n\n\n\n<p>Project Code &#8211; This is my current code but the error handling needs to be improved.. It has the basic functionality as long as the users doesn&#8217;t make a mistake with their typing <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def calculator(f_num, op, s_num):\n    if op == \"+\":\n        answer=float(f_num) + float(s_num)\n    elif op == \"-\":\n        answer=float(f_num) - float(s_num)\n    elif op == \"*\":\n        answer = float(f_num) * float(s_num)\n    elif op == \"\/\":\n        answer = float(f_num) \/ float(s_num)\n    else:\n        print(\"Invalid operator. Please try again.\")\n        return\n    return answer\n\nreturned_answer = calculator(input(\"What's the first number? \"), input(\"Pick an operator: \\n+\\n-\\n*\\n\/ \"), input(\"What's the second number? \"))\n\nresponse = input(f\"Would you like to continue with the answer 'yes' or 'no'  {returned_answer}: \")\n\nwhile response == \"yes\".lower():\n    returned_answer = calculator(returned_answer, input(\"what operation would you like: \\n+\\n-\\n*\\n\/ \"), input(\"What's the next number? \"))\n    print(returned_answer)\n    response = input(f\"Would you like to continue with the answer {returned_answer} type 'yes':\")\n    if response != \"yes\".lower():\n        print(\"Invalid input. Please try again.\")\n\nprint(\"Thank you for choosing Calculator\")<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Coding Exercise: Project Code &#8211; This is my current code but the error handling needs to be improved.. It has the basic functionality as long as the users doesn&#8217;t make a mistake with their typing<\/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":true,"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-1361","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-lX","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1361","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=1361"}],"version-history":[{"count":1,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"predecessor-version":[{"id":1362,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1361\/revisions\/1362"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}