Menu

Building My Second Python Project: A Number Guessing Game! ๐ŸŽฎ
๐Ÿ“ฐ

Building My Second Python Project: A Number Guessing Game! ๐ŸŽฎ

DEV Community: beginnersยทAaditya Parag Pataniยท4 days ago
#6U46GzRD
#devtobeginners#devto#dev#python#number
Reading 0:00
15s threshold

Aaditya Parag Patani

Building My Second Python Project: A Number Guessing Game! ๐ŸŽฎ

Hi DEV Community! ๐Ÿ‘‹

After building a simple calculator as my very first Python project, I wanted to try something a bit more interactive. So, I built a Number Guessing Game!

Itโ€™s a small project, but it helped me get more comfortable with loops, conditionals, and using Python's built-in random module.

Here is the Python code I wrote:

import random

lucky_number = random.randint(1, 50)

while True:
    your_number = int(input("Enter a number between 1 and 50: "))

    if your_number > lucky_number:
        print("Too high")
    elif your_number < lucky_number:
        print("Too low")
    else:
        print("Congratulations!! You guessed the correct number. \nYou won the game")
        break

print("-------------------Game Over-----------------")

Enter fullscreen mode Exit fullscreen mode