-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordGuess.py
More file actions
54 lines (39 loc) · 1.21 KB
/
WordGuess.py
File metadata and controls
54 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import random
print('WORD GUESSING GAME')
name = str(input('Enter name: '))
print('WELCOME'+' '+ name.upper())
words = ['rainbow', 'computer', 'science', 'programming',
'python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board', 'geeks']
word = random.choice(words)
chances = 12
guessed = set()
while chances > 0:
chances -=1
character = str(input('Enter character: '))
if not character.isalpha() or len(character)!=1:
print('ENTER A VALID LETTER')
continue
if character in guessed:
print('Already guessed')
continue
guessed.add(character)
if character not in word:
print(f'Character not in word, hint ->{word[:3]}')
else:
print('Good guess')
if all(char in guessed for char in word):
print(f'CONGRATS word is {word}')
break
elif chances == 0 and guessed != word:
print('Lost')
'''
w = str(input('Enter a word, '+ f'hint is {word[:3]}:'))
if w==word:
print('BRAVO!')
break
elif len(w)==0 or not w.isalpha():
print('ENTER VALID WORD')
elif chances==0 and w!=word:
print(f'YOU LOOSE! ,word is {word}')
'''