I am new at programming. I wrote a small program in python and converted it to .exe file with pyinstaller
. Now when i try to open the .exe file a black screen appears and closes immediately. I was able to get a screenshot:
I saw a solution like adding input()
at the end of the code but it didn't work either. My code:
import random
print("Hello, what is your name?")
name = str(input())
print("Well, " + name + ", I think of a number between 1 and 1000. Can you guess this number in 10 chances?")
number = random.randint(1, 1001)
for guessTaken in range(1, 11):
print("Take a guess")
guess = int(input())
if guess > number:
print("The number you think is too high")
elif guess < number:
print("The number you think is too low")
else:
break
if guess == number:
print("OK, " + name + ", you guessed the number in " + str(guessTaken) + " guesses")
else:
print("Unfortunatelly, you couldn't find the number. The number is " + str(number))
This worked for me:
Had the same issue but then realized that I was inadvertently trying to execute the file in the
build
folder instead of thedist
folder.Looks like you might be making the same mistake from your traceback so see if using the executable in
dist
doesn't fix it for you