第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我運行程序時,“無”一直顯示

當我運行程序時,“無”一直顯示

有只小跳蛙 2021-03-06 11:11:54
每當我運行我創(chuàng)建的計算器程序時,它都可以正常工作,但文本“ 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=2def 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, Welcomethese are your options1. add2. subNone    <-------------------------(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+bdef sub():    print 'choose 2 numbers to subract'    a=input('subract this')    b=input('from this')    print b-adef mul():    print 'choose 2 numbers to multiply'    a=input("multiply this")    b=input("by this")    print b*adef div():    print 'choose what numbers your want to divide'    a=input('divide this')    b=input('by this')    print a/bdef exp():    print 'choose your number you want to exponentiate'    a=input('multiply this')    b=input('by the power of this')    print a**bdef 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()
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經(jīng)驗 獲得超5個贊

那是因為該函數(shù)menu()沒有返回任何東西,默認情況下,python中的一個函數(shù)會返回None


>>> def func():pass

>>> print func()  #use `print` only if you want to print the returned value

None

只需使用:


menu() #no need of print as you're already printing inside the function body.

從和sys()刪除后的新版本。不必在每個函數(shù)內(nèi)部使用,只需在其末尾調(diào)用該函數(shù)即可。return menu()add()sub()return menu()menu()while loop


def sys():

    while True:

        a = input("please choose")

        if a == 1:

            add()    # call add(), no need of print as you're printing inside add() itself

        elif a==2: 

            sub()  

        menu()       # call menu() at the end of the loop

while loop==2實際上loop==2首先計算表達式,如果是,True則while loop繼續(xù),否則立即中斷。在您的情況下,因為您不更改loop變量的值,所以可以簡單地使用while True。


>>> loop = 2

>>> loop == 2

True


查看完整回答
反對 回復 2021-03-27
  • 1 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號