DEV Community

Netsai
Netsai

Posted on

1

Let's create a secret word game with python to understand the use of "if and while statements"!

secret_word = "Whileloop"
guess =""
guess_count = 0
guess_limit = 3
out_of_guesses = False

while guess != secret_word and not out_of_guesses:
    if guess_count < guess_limit:
        guess = input("Enter your word: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("out of Guesses, You looooooose the game 🫠")
else:
    print("You winπŸŽ‰πŸŽ‰")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay