keyboard_arrow_left keyboard_arrow_right
Pablo's Project

Hangman Game

About Pablo

My name is Pablo Rodriguez, and I am in 8th Grade. One of my favorite things to do is to study the natural sciences; such as biology, chemistry, and geology. I also enjoy reading both fiction and non-fiction books.

Pablo's project details:

Hangman is a popular game that is played in many places around the world. For my project, I decided to make this game playable through Python. The goal of the game is to guess a mystery word off of guessing letters correctly one at a time.
1. Click on the “RUN” button below to run the program.
2. This is very interesting. And I hope you all would surely enjoy and like it.
Click on
   
play icon below to run the code and see the magic unfolding.

import random
print(" ")
print("Welcome to Hangman!")
words = [["m","o","u","s","e"],["p","l","a","n","e"],["p","h","o","n","e"],["p","a","r","t","y"],
        ["h","o","u","s","e"],["p","h","o","t","o"],["g","l","a","s","s"],["s","h","a","r","e"],
        ["m","e","t","a","l"],["s","a","u","c","e"],["m","a","s","k","s"],["c","o","v","i","d"],
        ["w","h","a","l","e"],["m","o","n","e","y"],["o","l","i","v","e"],["a","p","p","l","e"],
        ["c","l","o","c","k"],["c","o","l","o","r"],["g","h","o","s","t"],["j","u","i","c","e"],
        ["h","a","p","p","y"],["w","a","t","e","r"],["f","r","u","i","t"],["h","o","r","s","e"],
        ["t","i","g","e","r"],["c","a","m","e","l"],["g","r","e","e","n"],["e","a","r","t","h"]]
rounds = int(input("How many rounds do you want to play?(Enter a number): "))
r = 0
while r < rounds:
    fails = 0
    a = 0
    spots = ["_", "_", "_", "_", "_"]
    currentword = random.choice(words)
    print("Round", r + 1)
    while a < 5 and fails < 15:
        if a == 0 and fails == 0:
            guess = str(input("""
_ _ _ _ _

    Guess any letter: """))
                
        else:
            guess = str(input("Guess another letter: "))
        for i in range(0,5):
            if guess in spots[i]:
                print("You already guessed", guess)  #in case the user selects again a succesful letter
            if guess in currentword[i] and guess not in spots[i]:
                spots[i]=guess
                print(spots[0],spots[1],spots[2],spots[3],spots[4])
                print("Correct!")
                a += 1
        if guess not in currentword:
            print("Incorrect")
            fails += 1
        if fails == 15:
            print("""You lose. Better luck next time
You guessed the wrong letter 15 times
The correct answer was""", currentword[0]+currentword[1]+currentword[2]+currentword[3]+currentword[4]+'.')
    r += 1
    words.remove(currentword)
print("Thanks for Playing!!!")
                                         
Name: Pablo Rodriguez
Grade: 8
  My son loves his Python course. He has now become very interested in coding and he has learned a lot. He also has a great instructor. I would definitely recommend the course.
Parents of Pablo Rodriguez
Be the Next Creator like :