-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimal Guessing Game.py
93 lines (67 loc) · 2.78 KB
/
Animal Guessing Game.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import random
from math import *
#lists of animals types
water = [
"Crab", "Fish", "Seal", "Shark", "Starfish", "Whale", "Penguin",
"Jellyfish", "Lobster", "Pelican", "Seahorse", "Walrus", "Shrimp",
"Oyster", "Clams", "Seagull", "Dolphin", "Cormorant", "Otter", "Angelfish",
"Blue Whale", "Tuna", "Salmon", "Goldfish", "Barnacle", "Bull Shark",
"Clownfish", "Cod", "Conch", "Coral", "Cuttlefish", "Dolphin", "Fan Worm",
"Flounder", "Flying Fish", "Grouper", "Haddock", "Halibut", "Herring",
"Humpback Whale", "Jellyfish", "Ling", "Lobster", "Mackerel", "Mussel"
]
wild = [
"Tiger", "Lion", "Elephant", "Leopard", "Panther", "Cheetah", "Wolf",
"Hyena", "Giraffe", "Deer", "Zebra", "Gorilla", "Monkey", "Bear",
"Squirrel", "Kangaroo", "Crocodile", "Panda", "Squirrel", "Mongoose",
"Koala Bear", "Wombat", "Meerkat", "Otter", "Hedgehog", "Raccoon", "Hare",
"Mole", "Rabbit", "Alligator", "Oryx", "Elk", "Badger", "Pangolin",
"Camel", "Coyote", "Bison", "African Elephant", "Antelope", "Alpine Goat",
"Beaver", "Baboon", "Bat", "Giant Panda", "Chihuahua", "Orangutan"
]
sky = [
"Eagle", "Hawk", "Emu", "Falcon", "Owl", "Bat", "Chihuahua", "Guinea Pig"
]
#----------------------------------------
# Randomly choose an animal from each category
animals = [random.choice(water) , random.choice(wild) , random.choice(sky)]
picked_animal=random.choice(animals)
print("")
# Check if a string contains spaces
def spaces(x):
for i in x:
if i == " ":
return True
return False
# Check if the picked animal's name contains spaces
if spaces(picked_animal)==True:
print ("this name has an *SPACE*")
print(picked_animal)
print("")
# Determine the category of the picked animal
if picked_animal in sky:
print("animal is from the sky")
elif picked_animal in wild:
print("animal is from the wild")
else:
print("animal is from the water")
# Initialize the guessed animal with hidden characters
guessed_animal = picked_animal[0] + '*' * (len(picked_animal) - 1)
print("The animals start with the letter", guessed_animal)
print("")
attempts=0
for i in range(3): # Allow three attempts
attempts += 1
user_guess = input("Enter your guess: ").capitalize()
if user_guess == picked_animal:
print("Congratulations! You guessed correctly.")
break
else:
# Reveal one more character if the guess is incorrect
revealed_chars = min((i+1) + 1, len(picked_animal)-1)
guessed_animal = picked_animal[:revealed_chars] + '*' * (len(picked_animal) - revealed_chars)
while attempts<3:
print("Incorrect guess. The animals start with the letters", guessed_animal)
break
print("")
print("The correct animal was:", picked_animal)