My First Python Project: Creating a Simple Guessing Game

In this article, I share my experience creating a classic guessing game as my first Python project. I also discuss my challenges in converting the .py file to an executable (.exe) and sharing it with others. Learn about tools like PyInstaller and VirusTotal, as well as tips for sharing your program safely and effectively. Plus, find the full code for the game!
My first Python project was a classic simple game that many beginners create when learning the language. The computer randomly selects a number from 1 to 99, and the user has seven attempts to guess it. I chose seven because it allows you to always win if you go to the middle of the range each time. For example, you start with 50, and if the computer says "higher," you go to 75, and so on.
This was the first time I used while loops and functions that run when called. It was also my first time converting a .py file to an executable (.exe) to run on computers without Python installed.

For this, I used the well-known PyInstaller, which can be quite troublesome. Firstly, it doesn't create a single .exe file if you have images or other files in your program, so you need to carry all of them together with the .exe in a .rar file or something similar.
Secondly, some antivirus software, including Google's, incorrectly identify your .exe file as a virus. Google is not an antivirus, but it won't allow you to send the .exe file via email or even share it through Google Drive.
The solution? You can do two things. First, upload the file to VirusTotal , see which antiviruses recognize it as a virus, and send a false positive report, at least to the major antiviruses widely used.

To share a program, first compress it with a password and then upload it to Google Drive or any server you have for sharing. Personally, I use Microsoft's OneDrive, which provides 5 GB of free space and works great.
If you're interested, you can download the game's exe file here. It doesn't require installation and is completely safe, although Google may flag it as an uncommon download.
Overall, this project was a great learning experience for me. It allowed me to gain familiarity with important concepts such as loops, functions, and executable file conversion. I also learned about some potential challenges in sharing my program with others, such as antivirus software false positives. However, by using tools like VirusTotal and password-protecting compressed files, I was able to overcome these challenges and successfully share my project with others.
Below is the full code for my first program.
import numpy as np
def my_first_game():
num_of_guesses = 1
max_num_of_guesses = 7
out_of_guesses = False
# The number we are looking for is auto generated
gold_num = np.random.randint(1, 99)
your_num = input("Can you find the number I thought? It's between 1-99 and you have 7 guesses: ")
try:
while int(gold_num) != int(your_num) and not out_of_guesses:
if num_of_guesses < max_num_of_guesses:
if int(gold_num) < int(your_num) < 100:
print("Go DOWN please")
elif int(gold_num) > int(your_num) > 0:
print("Go UP please")
elif int(your_num) >= 100:
print("No numbers above 99 are allowed!")
num_of_guesses -= 1
elif int(your_num) <= 0:
print("No negative numbers or 0 are allowed!")
num_of_guesses -= 1
num_of_guesses += 1
your_num = input("Try again: ")
else:
out_of_guesses = True
print("Sorry, you lost!")
else:
if int(gold_num) == int(your_num):
print("You found it, you bastard!")
except ValueError:
print("This is not a number, the program will terminate.")
my_first_game()
while True:
play_or_quit = input("Press 'p' to play again or 'q' to quit: ")
if play_or_quit.lower() == "p":
my_first_game()
else:
if play_or_quit.lower() == "q":
exit(0)