guess the word python

Solutions on MaxInterview for guess the word python by the best coders in the world

showing results for - "guess the word python"
Ida
17 Nov 2019
1import random
2# Put words to guess inside the array 
3words = []
4 
5word = random.choice(words)
6n = len(word)
7 
8print("Guess the word")
9
10guesses = ''
11#number of turn is equal to the legnth of the word stored in 'n'
12turns = n
13 
14 
15while turns > 0:
16     
17    #counts the number of wrong choices
18    failed = 0
19    
20    for char in word:
21        if char in guesses:
22            print(f"\t{char}")
23        else:
24            print(f"\t_")
25            failed += 1
26             
27 
28    if failed == 0:
29        print("Congratulations! you Win!\n")
30        print(f"The word is: {word}")
31        break
32     
33
34    guess = input("\nguess a letter: ")
35    guesses += guess
36     
37    #decrements the turns for every wrong guess
38    if guess not in word:
39        turns -= 1
40        print("Wrong")
41        print(f"You have, {turns} more guesses")
42
43        if turns == 0:
44            print(f"You Loose, The word is {word}.")