Logic Puzzles
Logic Puzzles
class LogicPuzzleGame:
def __init__(self):
self.puzzles = [
{
"question": "I am an odd number. Take away one letter and I become
even. What am I?",
"answer": "seven"
},
{
"question": "What comes once in a minute, twice in a moment, but
never in a thousand years?",
"answer": "the letter m"
},
{
"question": "I am not alive, but I grow; I don't have lungs, but I
need air; I don't have a mouth, but water kills me. What am I?",
"answer": "fire"
},
{
"question": "The more of this there is, the less you see. What is
it?",
"answer": "darkness"
},
{
"question": "What has keys but can't open locks?",
"answer": "a piano"
}
]
def start_game(self):
print("Welcome to the Logic Puzzles Game!")
print("Try to solve the puzzles below. Type 'exit' to quit the game.")
self.play_game()
def play_game(self):
score = 0
random.shuffle(self.puzzles) # Shuffle the puzzles to give variety
for i, puzzle in enumerate(self.puzzles, start=1):
print(f"\nPuzzle {i}:")
print(puzzle["question"])
player_answer = input("Your answer: ").strip().lower()
if player_answer == puzzle["answer"]:
print("Correct! Well done.")
score += 1
else:
print(f"Sorry, the correct answer is: {puzzle['answer']}")
if self.ask_to_continue():
continue
else:
break
def ask_to_continue(self):
while True:
choice = input("\nDo you want to continue to the next puzzle? (yes/no):
").strip().lower()
if choice == 'yes':
return True
elif choice == 'no':
print("Thanks for playing! Exiting the game.")
return False
else:
print("Invalid input, please enter 'yes' or 'no'.")