我似乎無法運行這個簡單的程序。基本上我想要做的是輸入一個我的函數立方體的數字。然後檢查這個數字是否可以被三整除。python中的函數真的很簡單
print "This program checks if a number is divisible by three"
def cube(number): # this is my function which is defined
return number**3 # I am confused about the return. does the program exit?
print number
if number%3==0:
print "Yes"
else:
print "No"
打印 「此程序檢查是否一個數字是由三個整除」 DEF立方體(數目): 返回數** 3 打印數 如果號碼%3 == 0: 打印 「是」 否則: 打印「否」 – user4081147 2014-09-25 21:23:39
爲什麼你要將數字立方體呢? – 2014-09-25 21:25:19
該程序不會退出,但功能結束。另外,你從不*調用*函數。閱讀教程:https://docs.python.org/2/tutorial/controlflow.html#defining-functions – jonrsharpe 2014-09-25 21:25:33