0% found this document useful (0 votes)
4 views2 pages

Logic Puzzles

Game

Uploaded by

user-602108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Logic Puzzles

Game

Uploaded by

user-602108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

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

print(f"\nGame Over! Your score is {score} out of {len(self.puzzles)}.")

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'.")

# Start the game


if __name__ == "__main__":
game = LogicPuzzleGame()
game.start_game()

You might also like