Posts

Showing posts from May, 2020

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