简体   繁体   English

我的python代码运行了几次,但是一旦我关闭计算机或执行其他操作,它就不会再次运行

[英]My python code runs a few times but as soon as I close my computer or do something else, it doesn't run again

Running this code a few times presents no issues. 几次运行此代码不会出现问题。 Upon attempting to show a friend, it doesn't work. 尝试向朋友显示时,此操作无效。 It just hangs after the input. 它只是在输入后挂起。 It's worked quite a few times before but never again unfortunately. 它已经工作了好几次,但不幸的是再也没有。

I've tried rewriting the code in brackets, rewriting the code to a local directory instead of the Google Drive folder I have and I've even tried rewriting from scratch in regular notepad. 我尝试将代码重写在方括号中,将代码重写到本地目录而不是我拥有的Google Drive文件夹中,甚至尝试在常规记事本中从头开始重写。 All this was tried in case some sort of encoding issue had occured. 如果发生某种编码问题,请尝试所有这些操作。 No such luck. 没有这种运气。 I figure something is wrong with the interpreter but I'm not sure how to remedy the situation. 我认为口译员出了点问题,但是我不确定如何解决这种情况。

def bin2dec():
    bin = []
    a = int(input("What number are you converting to binary?: "))
    while a > 0:
        if a % 2 == 0:
            bin.insert(0, 0)
            a = a/2
        elif a % 2 == 1:
            bin.insert(0, 1)
            a = a/2-0.5
    else:
        #repetition
        print("Your binary equivalent is:", bin)
        repeat = input("Would you like to convert another binary number?: ")
        if repeat == "yes":
            bin2dec()

bin2dec()

Oh....welp. 哦。。。 It seems the problem was actually that I somehow installed two versions of pythons and I guess they had been interfering with each other. 看来问题出在实际上我以某种方式安装了两个版本的python,我想它们一直在互相干扰。 Reason I'm not deleting this Q is because I'm sure I'm not the only one who's made this mistake. 我之所以不删除此问题,是因为我确定不是唯一一个犯此错误的人。 However, others have probably made this mistake in an effort to ensure compatibility between versions. 但是,其他人可能在确保版本之间兼容性方面犯了这个错误。 Bad idea. 馊主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在我的计算机上运行代码时,它不会运行,但它适用于教程 - The code doesn't run while I run it on my computer but it works on the tutorial 我的代码在 Spyder 上运行,但它不在 Anaconda Prompt 上运行 - My code runs on Spyder but it doesn't run on Anaconda Prompt 我能否以某种方式合并这些类,这样我就不必一次又一次地编写它,并且我的 python 代码不会变得多余 - Can I somehow merge these classes such that I don't have to write this again and again and my python code doesn't get redundant Python3我的代码不想再次输入 - Python3 My Code Doesn't want input again 我的代码在我的计算机上完美运行,但在服务器上执行时却不行? PYTHON - My code runs perfectly on my computer but not when executed on server? PYTHON 连续运行python代码后,我的计算机最终崩溃 - Upon successive runs of my python code eventually crashes my computer 我的脚本运行一次,如何将其编码为始终运行? - My script runs once, how do I code it to run always? 如何让我的 python 代码再次运行 - How can I get my python code to run again 为什么条件“ else”在我的python代码中不起作用 - Why condition “else” doesn't work in my python code 这段代码有问题吗? 还是我的电脑? - Is there something wrong with this code? Or my computer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM