DEV Community

Cover image for Simple Python Password Game for Beginners
Sami Ammar
Sami Ammar

Posted on

Simple Python Password Game for Beginners

I created a small password guessing game in Python where the player has to guess the correct password to win.
The goal is to practice using loops, conditions, and user input in Python.
This project is great for beginners who want to improve their logic and coding skills.

Here is the Python code for the password game:

Simple Password Guessing Game in Python

SECRET_PASSWORD = "python123" # you can change this password
MAX_ATTEMPTS = 3

def main():
print("=== Password Guessing Game ===")
print("You have 3 attempts to guess the correct password.\n")

for attempt in range(1, MAX_ATTEMPTS + 1):
    guess = input(f"Attempt {attempt}: Enter your password: ")

    if guess == SECRET_PASSWORD:
        print(" Access Granted! You guessed the password correctly.")
        break
    else:
        print(" Wrong password.")

    if attempt == MAX_ATTEMPTS:
        print("\nGame Over! You have used all attempts.")
Enter fullscreen mode Exit fullscreen mode

if name == "main":
main()

Conclusion:
This simple Python password game is an easy way to practice programming basics like loops, conditions, and user input. Try modifying the secret password or adding new features such as unlimited attempts or hints to make the game more fun!_**

Top comments (0)