{"id":1322,"date":"2024-12-27T14:54:41","date_gmt":"2024-12-27T13:54:41","guid":{"rendered":"https:\/\/vroamam.com\/wordpress\/?p=1322"},"modified":"2024-12-27T14:54:41","modified_gmt":"2024-12-27T13:54:41","slug":"day-7-hangman","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/day-7-hangman\/","title":{"rendered":"Day 7 &#8211; Hangman"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Day 7 Goals<\/li>\n\n\n\n<li>Approaching Complex Problems<\/li>\n\n\n\n<li>Step 1 &#8211; Pick a Random Word<\/li>\n\n\n\n<li>Step 2 &#8211; Replacing Blanks with Guesses<\/li>\n\n\n\n<li>Step 3 &#8211; Checking of the Player has won<\/li>\n\n\n\n<li>Step 4 &#8211; Keeping Track of Players Lives<\/li>\n\n\n\n<li>Step 5 &#8211; Improving the User Experience<\/li>\n<\/ul>\n\n\n\n<p>Project Hangman &#8211; The completed version<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nimport hangman_words\nimport hangman_art\n# TODO-1: - Update the word list to use the 'word_list' from hangman_words.py\n\nlives = 6\n\n# TODO-3: - Import the logo from hangman_art.py and print it at the start of the game.\n\nchosen_word = random.choice(hangman_words.word_list)\nprint(chosen_word) # this is here to facilitate easy testing - remove it to play the game properly\n\nplaceholder = \"\"\nword_length = len(chosen_word)\nfor position in range(word_length):\n    placeholder += \"_\"\nprint(\"Word to guess: \" + placeholder)\n\ngame_over = False\ncorrect_letters = &#91;]\n\nwhile not game_over:\n# TODO-6: - Update the code below to tell the user how many lives they have left.\n    print(f\"****************************{lives}\/6 LIVES LEFT****************************\")\n    guess = input(\"Guess a letter: \").lower()\n# TODO-4: - If the user has entered a letter they've already guessed, print the letter and let them know.\n    if guess in correct_letters:\n        print(f\"You've already guessed {guess}\")\n\n\n    display = \"\"\n\n    for letter in chosen_word:\n        if letter == guess:\n            display += letter\n            correct_letters.append(guess)\n        elif letter in correct_letters:\n            display += letter\n        else:\n            display += \"_\"\n\n    print(\"Word to guess: \" + display)\n\n# TODO-5: - If the letter is not in the chosen_word, let them know it's not in the word.\n#  e.g. You guessed d, that's not in the word. You lose a life.\n\n    if guess not in chosen_word:\n        lives -= 1\n        print(f\"You guessed {guess}, that's not in the word. You lose a life.\")\n\n        if lives == 0:\n            game_over = True\n\n# TODO 7: - Update the print statement below to give the user the correct word they were trying to guess.\n            print(f\"*********************** YOU LOSE - the word was {chosen_word} **********************\")\n\n    if \"_\" not in display:\n        game_over = True\n        print(\"****************************YOU WIN****************************\")\n\n# TODO-2: - Update the code below to use the stages List from the file hangman_art.py\n    print(hangman_art.stages&#91;lives])\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Project Hangman &#8211; The completed version<\/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-1322","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-lk","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1322","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=1322"}],"version-history":[{"count":2,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1322\/revisions"}],"predecessor-version":[{"id":1324,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1322\/revisions\/1324"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}