-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword challenges
More file actions
46 lines (31 loc) · 994 Bytes
/
word challenges
File metadata and controls
46 lines (31 loc) · 994 Bytes
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
import random
name = input("What is your name? ")
print("Good Luck !", name)
words = ['rainbow', 'computer', 'science', 'programming',
'python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board', 'geeks']
word = random.choice(words)
print("Guess the characters")
guesses = ''
turns = 12
while turns > 0:
failed = 0
for char in word:
if char in guesses:
print(char, end=" ") # Prints guessed letters on the same line
else:
print("_", end=" ") # Fix: Keeps underscores on the same line
failed += 1
print() # Moves to the next line for better formatting
if failed == 0:
print("You Win")
print("The word is:", word)
break
guess = input("Guess a character: ")
guesses += guess
if guess not in word:
turns -= 1
print("Wrong")
print("You have", turns, "more guesses")
if turns == 0:
print("You Lose")