[英]The code doesn't run while I run it on my computer but it works on the tutorial
[英]My python code runs a few times but as soon as I close my computer or do something else, it doesn't run again
幾次運行此代碼不會出現問題。 嘗試向朋友顯示時,此操作無效。 它只是在輸入后掛起。 它已經工作了好幾次,但不幸的是再也沒有。
我嘗試將代碼重寫在方括號中,將代碼重寫到本地目錄而不是我擁有的Google Drive文件夾中,甚至嘗試在常規記事本中從頭開始重寫。 如果發生某種編碼問題,請嘗試所有這些操作。 沒有這種運氣。 我認為口譯員出了點問題,但是我不確定如何解決這種情況。
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()
哦。。。 看來問題出在實際上我以某種方式安裝了兩個版本的python,我想它們一直在互相干擾。 我之所以不刪除此問題,是因為我確定不是唯一一個犯此錯誤的人。 但是,其他人可能在確保版本之間兼容性方面犯了這個錯誤。 餿主意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.