我是编程新手。我用 python 编写了一个小程序并将其转换为 .exe 文件 pyinstaller
。现在,当我尝试打开 .exe 文件时,出现黑屏并立即关闭。我能够得到一个截图:
我看到了一个解决方案,比如在代码末尾添加 input()
但它也没有用。我的代码:
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))
原文由 Cavid 发布,翻译遵循 CC BY-SA 4.0 许可协议
这对我有用:
(来源: https ://stackoverflow.com/a/54119819/4607733)