Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from timeit import default_timer as timer
- from random import randrange
- # 1. Python program to read file word by word
- # Opening the text file
- words = list()
- with open('words.txt', 'r') as file:
- for line in file:
- for word in line.split():
- words.append(word)
- # print(words)
- # print("There are " + str(len(words)) + " words")
- print()
- print("*********************************************************************************")
- print("*********************************************************************************")
- print("Welcome to the 'Hangman Game'. You will have to make 2 choices to start the game.")
- # 2. Take the user's choices as data
- incorrect = int(input("1. How many incorrect answers do you want to have? "))
- while incorrect <= 0 or incorrect > 25 or incorrect != int(incorrect):
- incorrect = int(input("1. How many incorrect answers do you want to have? "))
- NLimit = int(input("2. What minimum word length do you want? "))
- while NLimit < 4 or NLimit > 16:
- NLimit = int(input("2. What minimum word length do you want? "))
- # 3. Randomize the word according to given criteria
- word = words[randrange(0, len(words))]
- # print(word)
- while len(word) < NLimit:
- word = words[randrange(0, len(words))]
- # print(word)
- # 4. Let the game begin
- print()
- print(word)
- letters = [word[i] for i in range(len(word))]
- # I will make a list in which I match each letter with 0 or 1
- # The element will be 0 if this letter is not revealed yet
- foundLetters = [0 for _ in range(len(letters))]
- print("*********************************************************************************")
- attemptsRemaining = incorrect
- while attemptsRemaining > 0:
- print(attemptsRemaining)
- print("*********************************************************************************")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement