HangMan game in Python

It is a text based game where the computer will choose a random word and you have to guess it letter by letter.
Based on your choice of levels (easy/medium/hard), you will be given several choices to guess wrong alphabet.

pyCode

import random

import time

name = input("what is your name?\n")

print("Goodluck!! {}.".format(name))

words = ["mathematics", "science", "computer", "program", "probably"]

word = random.choice(words)

print("Easy medium or hard?")

guesses = ""

level = input("e/m/h\n")

if level.lower() == "e":

turns = 12

elif level.lower() == "m":

turns = 7

elif level.lower() == "h":

turns = 4

else:

print("Please enter a valid choice...")

start = time.time()

while turns > 0:

failed = 0

for char in word:

if char in guesses:

print(char)

else:

print("_")

failed += 1

if failed == 0:

print("You Win")

print("The word is {}".format(word))

break

guess = input("Guess a character:  ")

guesses += guess

if guess not in word:

turns -= 1

print("wrong")

print("You have {} more guesses..".format(turns))

if turns == 0:

print("You Loose")

stop = time.time()

print("You completed in {} seconds...".format(round(stop - start)))

____________________________________

@projectsofcode on INSTAGRAM



Comments

Popular posts from this blog

HangMan game in PYTHON

Tic-Tac-Toe (multiplayer) using pthon

Projects to consider as a bigener in PYTHON