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
添加回答
舉報