Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit f9593d9

Browse files
committed
-changed to only import load from json instead of import json
- convert the word to upper case before return the word.
1 parent 4cc178c commit f9593d9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

projects/Terminal_Based_Hangman_Game/hangman.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import random
2-
import json
2+
from json import load
33

44
#function to randomly get one word from words.py and convert the word to uppercase
55
def get_word():
66
with open('words.json') as json_file:
7-
data = json.load(json_file)
7+
data = load(json_file)
88

99
wordArray = data["word_list"]
1010
word = random.choice(wordArray)
11-
return word.upper()
11+
word = word.upper()
12+
return word
1213

1314
#function to play the game
1415
def play(word):
@@ -32,7 +33,7 @@ def play(word):
3233
while not guessed and tries > 0:
3334

3435
#Display message and ask for user input and convert it into uppercase
35-
guess = input("Please guess a letter: ").upper()
36+
guess = input("Please guess a letter or the word: ").upper()
3637

3738
#check the length of the user input and is it alpha or not
3839
if len(guess) == 1 and guess.isalpha():

0 commit comments

Comments
 (0)