简体   繁体   中英

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM