Building My Second Python Project: A Number Guessing Game! 🎮

2026-10-25来源 dev.to ProgrammingEnglish

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-----------------") 

原文:https://www.a8q9.cn/en/article/building-my-second-python-project-a-number-guessing-game-87e966.html

相关文章