codIng
import sys
[Link](encoding='utf-8')
import sqlite3
import random
from datetime import datetime
import os
# Use a safe path inside Pydroid3's app folder
db_path = [Link]([Link](), "guess_game_new.db")
# Connect to the database
conn = [Link](db_path)
cursor = [Link]()
# 1) Create tables
[Link]('''
CREATE TABLE IF NOT EXISTS words (
id INTEGER PRIMARY KEY AUTOINCREMENT,
word TEXT NOT NULL,
hint TEXT NOT NULL,
difficulty TEXT
)
''')
[Link]('''
CREATE TABLE IF NOT EXISTS scores (
id INTEGER PRIMARY KEY AUTOINCREMENT,
player TEXT,
score INTEGER,
difficulty TEXT,
date TEXT
)
''')
[Link]("SELECT COUNT(*) FROM words")
count = [Link]()[0]
print("Words currently in table:", count)
if count == 0:
starter_words = [
("python", "A popular programming language 🐍", "easy"),
("cell", "Basic unit of life 🧬", "easy"),
("heart", "Organ that pumps blood ❤", "easy"),
("water", "Liquid essential for life 💧", "easy"),
("plant", "Green organism that makes food 🌿", "easy"),
("sun", "The star at the center of our solar system ☀", "easy"),
("moon", "Earth’s natural satellite 🌙", "easy"),
("animal", "Living organism that moves 🐾", "easy"),
("river", "A flowing water body 🌊", "easy"),
("mountain", "A very tall landform ⛰", "easy"),
("teacher", "Person who teaches 🧑🏫", "easy"),
("light", "Opposite of dark 💡", "easy"),
("soil", "Earth’s upper layer for growing plants 🌱", "easy"),
("rain", "Water falling from clouds 🌧", "easy"),
("leaf", "Green part of a plant 🍃", "easy"),
("fish", "An aquatic animal 🐟", "easy"),
("nucleus", "Control center of the cell 🧬", "medium"),
("friction", "Force that opposes motion ⚙", "medium"),
("voltage", "Electric potential difference ⚡", "medium"),
("density", "Mass per unit volume ⚖", "medium"),
("galaxy", "A massive group of stars 🌌", "medium"),
("hormone", "Chemical messenger in the body 🧠", "medium"),
("ecosystem", "Interaction of living and nonliving things 🌍", "medium"),
("climate", "Weather over a long period 🌦", "medium"),
("glacier", "Large, slow-moving ice mass ❄", "medium"),
("decimal", "Number with a dot (like 3.14) ➗", "medium"),
("energy", "Ability to do work 🔋", "medium"),
("circuit", "Path for electric current ⚡", "medium"),
("respiration", "Process of releasing energy from food 🫁", "medium"),
("digestive", "System that processes food 🍽", "medium"),
("habitat", "Natural home of an organism 🌿", "medium"),
("mitochondria", "Powerhouse of the cell 🔋", "hard"),
("photosynthesis", "How plants make food using sunlight 🌞", "hard"),
("metamorphosis", "Change from caterpillar to butterfly 🦋", "hard"),
("biodiversity", "Variety of life forms on Earth 🌎", "hard"),
("precipitation", "Rain, snow, or hail falling 🌧", "hard"),
("chromatography", "Technique to separate mixtures 🎨", "hard"),
("equilibrium", "Balanced state ⚖", "hard"),
("neurotransmitter", "Chemical that sends signals in brain 🧠", "hard"),
("photosphere", "Visible outer layer of the Sun ☀", "hard"),
("thermodynamics", "Study of heat and energy 🔥", "hard"),
("homeostasis", "Maintaining stable internal conditions 🧬", "hard"),
("osmosis", "Movement of water across a membrane 💧", "hard"),
("ionization", "Process of forming ions ⚛", "hard"),
("morphology", "Study of structure and form 🔬", "hard")
]
[Link](
"INSERT INTO words (word, hint, difficulty) VALUES (?, ?, ?)",
starter_words
)
[Link]()
print("Starter words inserted.")
else:
print("Starter words already present, no need to insert.")
# --- GAME FUNCTIONS ---
def show_menu():
print('''
===============================
🎮 GUESS THE WORD GAME 🎮
1. Play Game
2. View Scores
3. Add New Word (Admin)
4. Exit
===============================
''')
def play_game():
player = input("Enter your name: ").capitalize()
# Choose difficulty
print("\nSelect Difficulty Level:")
print("1. Easy\n2. Medium\n3. Hard")
choice = input("Enter choice (1/2/3): ")
if choice == '1':
level = "easy"
points = 5
elif choice == '2':
level = "medium"
points = 10
elif choice == '3':
level = "hard"
points = 15
else:
print("Invalid choice! Defaulting to Easy.")
level = "easy"
points = 5
print(f"\n🧠 You chose '{[Link]()}' level. Let's begin!\n")
score = 0
rounds = int(input("How many rounds do you want to play? "))
for i in range(rounds):
[Link](
"SELECT word, hint FROM words WHERE difficulty=? ORDER BY RANDOM()
LIMIT 1",
(level,)
)
data = [Link]()
if not data:
print("No words found for this difficulty level.")
break
word, hint = data[0], data[1]
print(f"\nRound {i+1}:")
print(f"Hint: {hint}")
guess = input("Your Guess: ").strip().lower()
if guess == word:
print("✅ Correct!")
score += points
else:
print(f"❌ Wrong! The correct word was '{word}'.")
print(f"\n🎯 Final Score for {player}: {score} points ({[Link]()}
level)")
[Link](
"INSERT INTO scores (player, score, difficulty, date) VALUES (?, ?, ?,
?)",
(player, score, level, [Link]().strftime("%Y-%m-%d %H:%M:%S"))
)
[Link]()
print("💾 Score saved successfully!")
def view_scores():
print("\n🏆 LEADERBOARD 🏆")
[Link](
"SELECT player, score, difficulty, date FROM scores ORDER BY score
DESC LIMIT 10"
)
records = [Link]()
if not records:
print("No scores recorded yet!")
else:
for r in records:
print(f"{r[0]} - {r[1]} pts ({r[2].capitalize()} level) on
{r[3]}")
def admin_mode():
password = input("Enter admin password: ")
if password != "admin123":
print("❌ Wrong password! Access denied.")
return
print("\n✅ Admin Access Granted")
word = input("Enter new word: ").lower()
hint = input("Enter hint for the word: ")
diff = input("Enter difficulty (easy/medium/hard): ").lower()
if diff not in ["easy", "medium", "hard"]:
print("❌ Invalid difficulty! Must be easy, medium, or hard.")
return
[Link](
"INSERT INTO words (word, hint, difficulty) VALUES (?, ?, ?)",
(word, hint, diff)
)
[Link]()
print(f"✅ Word '{word}' added successfully to the {[Link]()} list!")
# --- MAIN PROGRAM LOOP ---
while True:
show_menu()
choice = input("Enter your choice: ")
if choice == '1':
play_game()
elif choice == '2':
view_scores()
elif choice == '3':
admin_mode()
elif choice == '4':
print("👋 Thanks for playing! Goodbye.")
break
else:
print("Invalid input. Try again.")
[Link]()
print("Database connection closed.")