Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on 06/11/2014
- Hangman
- Proven and tested on python 3.3.3
- @author: A01221672
- '''
- import random
- foo = ["duck","reddit", "dad", "magic", "frog", "sheep", "injured", "undertaker", "potatoe", "king", "north", "princess", "careful", "hammer", "shaman", "gorilla"]
- li0 = []
- bar = []
- hp1 = 7
- ho1 = random.choice(foo)
- qu1 = ""
- ca1 = 0
- '''
- with open("words.txt") as file:
- for line in file:
- li0.append(str(line.strip()))
- ho2 = random.choice(li0)
- '''
- #print(ho1)
- #random of a list returns an integer
- #len of an integer returns an integer with the amount of characters
- for x in range(len(ho1)):
- bar.append("_")
- #create a list with the amount of elements the word you are looking for has
- print("Welcome to the hangman game. You have 7 lives use them wisely.")
- print(bar)
- while True:
- qu1 = input("Guess a letter of the word: ")
- for i in range(len(ho1)):
- if ho1[i] == qu1:
- bar[i] = qu1
- ca1 = ca1 + 1
- if ca1 == 0:
- hp1 = hp1 - 1
- print("That is not a correct answer.")
- print(str(hp1) + " lives left.")
- print(bar)
- ca1 = 0
- if hp1 <= 0:
- break
- print("End of the game")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement