1

どうすればループを機能させることができますか? 1 や 2 などの入力を行っても、何も起こりません。

どうすればこれを解決できますか?

import os
while 1:
    os.system('cls')
    print("")
    print("1. Decimal to Binary")
    print("2. Binary to Decimal")
    print("3. Exit")
    choice = input('Input the number: ')
    if choice == "1":
        dec_to_bin()
    elif choice == "2":
        bin_to_dec()
    elif choice == "3":
        break;

def dec_to_bin():
    decimal = input('Input a number: ')
    a =  bin(decimal)[2:]
    print(a)

def bin_to_dec():
    binary = input('Input the binary: ')
    a = int('binary', 2)
    print(a)
4

1 に答える 1

1

input()Python 2 を使用しているため、 に変更する必要がありますraw_input()。プロンプトで入力する1と、文字列ではなく が返されます。input()int

于 2013-03-30T07:25:36.957 に答える