{"id":11,"date":"2025-12-05T15:09:16","date_gmt":"2025-12-05T15:09:16","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/m_vicander\/?p=11"},"modified":"2025-12-05T15:09:16","modified_gmt":"2025-12-05T15:09:16","slug":"how-to-make-hangman","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/m_vicander\/2025\/12\/05\/how-to-make-hangman\/","title":{"rendered":"How to make hangman"},"content":{"rendered":"\n<p>import random<\/p>\n\n\n\n<p>words = [&#8216;python&#8217;, &#8216;java&#8217;, &#8216;kotlin&#8217;, &#8216;javascript&#8217;, &#8216;ruby&#8217;, &#8216;swift&#8217;]<\/p>\n\n\n\n<p>#randomly choose a word from this list<\/p>\n\n\n\n<p>chosen_word = random.choice(words)<\/p>\n\n\n\n<p>word_display = [&#8216;_&#8217; for _ in chosen_word] &nbsp;# Create a list of underscores<\/p>\n\n\n\n<p>attempts = 8 &nbsp;# Number of allowed attempts<\/p>\n\n\n\n<p>print(&#8220;Welcome to hangman&#8221;)<\/p>\n\n\n\n<p>while attempts &gt; 0 and &#8216;_&#8217; in word_display:<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;\\n&#8221; + &#8216; &#8216;.join(word_display))<\/p>\n\n\n\n<p>&nbsp; &nbsp; guess = input(&#8220;Guess a letter: &#8220;).lower()<\/p>\n\n\n\n<p>&nbsp; &nbsp; if guess in chosen_word:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for index, letter in enumerate(chosen_word):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if letter == guess:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; word_display[index] = guess # reveal letter<\/p>\n\n\n\n<p>&nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;That letter doesnt appear in the word!&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; attempts -=1<\/p>\n\n\n\n<p># Game conclusion<\/p>\n\n\n\n<p>if &#8216;_&#8217; not in word_display:<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;You guessed the word!&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8216; &#8216;.join(word_display))<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;You survived&#8221;)<\/p>\n\n\n\n<p>else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;You ran out of attempts. The word was: &#8221; + chosen_word)<\/p>\n\n\n\n<p>&nbsp; &nbsp; print(&#8220;You lost!&#8221;)<\/p>\n\n\n\n<p>its a really simple and easy project to make <\/p>\n","protected":false},"excerpt":{"rendered":"<p>import random words = [&#8216;python&#8217;, &#8216;java&#8217;, &#8216;kotlin&#8217;, &#8216;javascript&#8217;, &#8216;ruby&#8217;, &#8216;swift&#8217;] #randomly choose a word from this list chosen_word = random.choice(words) word_display = [&#8216;_&#8217; for _ in chosen_word] &nbsp;# Create a list of underscores attempts = 8 &nbsp;# Number of allowed attempts print(&#8220;Welcome to hangman&#8221;) while attempts &gt; 0 and &#8216;_&#8217; in word_display: &nbsp; &nbsp; print(&#8220;\\n&#8221; [&hellip;]<\/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-11","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":12,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/posts\/11\/revisions\/12"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/m_vicander\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}