-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess the Word.py
55 lines (55 loc) · 1.88 KB
/
Guess the Word.py
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
55
from random import choice
count = 0
words = ["cat", "crocodile", "bear", "monkey", "mouse", "lion", "turtle", "rat", "racoon", "penguin", "kangaroo", "panda", "donkey", "hamster", "zebra", "elephant", "goat", "horse", "sheep", "deer", "giraffe", "koala", "leopard", "cheetah", "ostrich", "eagle", "spider", "tortoise", "shark", "whale", "chicken", "rhino", "marmot", "pig", "dolphin", "owl", "armadillo", "dog", "wolf", "cow", "skunk", "opossum", "camel", "alligator", "squirrel", "flamingo", "octopus", "squid", "snail", "hippopotamus", "yak"]
secret = choice(words)
# print(secret)
print("Try to guess my word. \n")
dashes = list("-" * len(secret))
print(" ".join(dashes))
while "-" in dashes:
letter = str(input("Enter letter: "))
if letter not in secret:
print("Try again!")
count = count + 1
else:
for i, el in enumerate(secret):
if el == letter:
dashes[i] = letter
count = count + 1
if dashes.count("-") == 0:
print("".join(dashes))
else:
print(" ".join(dashes))
count = count + 1
dashes = "".join(dashes)
print(f"You guessed the word it was {dashes}!")
print(f"You guessed it in {count} tries!")
again = str(input("Do you want to play again? "))
while again == "Yes":
count = 0
secret = choice(words)
# print(secret)
print("Try to guess my word. \n")
dashes = list("-" * len(secret))
print(" ".join(dashes))
while "-" in dashes:
letter = str(input("Enter letter: "))
if letter not in secret:
print("Try again!")
count = count + 1
else:
for i, el in enumerate(secret):
if el == letter:
dashes[i] = letter
count = count + 1
if dashes.count("-") == 0:
print("".join(dashes))
else:
print(" ".join(dashes))
count = count + 1
dashes = "".join(dashes)
print(f"You guessed the word it was {dashes}!")
print(f"You guessed it in {count} tries!")
again = str(input("Do you want to play again? "))
else:
print("Thank you for playing!")