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-----------------")
Top comments (0)