2

作成した電卓プログラムを実行すると、問題なく動作しますが、「None」というテキストが表示され続け、その理由がわかりません。コードは次のとおりです。

def add():
    print 'choose 2 numbers to add'
    a=input('add this')
    b=input('to this')
    print a+b
    return menu()
def sub():
    print 'choose 2 numbers to subract'
    a=input('subract this')
    b=input('from this')
    print b-a
    return menu()
def menu():
    print "hello, Welcome"
    print "these are your options"
    print "1. add"
    print "2. sub"
print menu()
loop=2
def sys():
    while loop==2:
        a=input("please choose")
        if a==1:
            print add()
        elif a==2:
            print sub()
        else:
            return menu(),sys()
print sys()

出力は次のとおりです。

hello, Welcome
these are your options
1. add
2. sub
None    <-------------------------(this is what I'm talking about)
please choose

それが誰かを助けるなら、ここに私の完成した電卓のコードがあります(私がそれを通り過ぎるとめちゃくちゃに見えますが、コピーして貼り付けると機能します)

def add():
    print 'choose 2 numbers to add'
    a=input('add this')
    b=input('to this')
    print a+b
def sub():
    print 'choose 2 numbers to subract'
    a=input('subract this')
    b=input('from this')
    print b-a
def mul():
    print 'choose 2 numbers to multiply'
    a=input("multiply this")
    b=input("by this")
    print b*a
def div():
    print 'choose what numbers your want to divide'
    a=input('divide this')
    b=input('by this')
    print a/b
def exp():
    print 'choose your number you want to exponentiate'
    a=input('multiply this')
    b=input('by the power of this')
    print a**b
def menu():
    print "hello, Welcome"
    print "these are your options"
    print "1. add"
    print "2. sub"
    print "3. mul"
    print "4. div"
    print "5. expo"
    print "0. to end"
menu()
def sys():
    while True:
        a=input("please choose")
        if a==1:
             add()
             menu()
        elif a==2:
             sub()
             menu()
        elif a==3:
             mul()
             menu()
        elif a==4:
             div()
             menu()
        elif a==5:
             exp()
             menu()
        elif a==0:
            break 
        else:
            return menu(),sys()
sys()
4

1 に答える 1