唔熟個programme 點run
唔知係個loop 入邊return 會點, 所以又另外拎左兩個variables 出黎return
依家睇返人地d ans, 似乎係loop 入邊return 都會即刻break 左個loop
其實到宜家都唔係好明python個return
點解唔用print 要用return? 用第2個方法多過1
1.
def multiply(num1,num2):
result = num1 * num2
return result
def minus(num3,num4):
result=num3-num4
return result
print(multiply(8,6)+minus(8,6))
=================================
2.
def multiply(num1,num2):
return num1 * num2
print(multiply(8,6))
def divide5_p(k):
for i in range(k):
if i%5==0 and i!=0:
print(i)
divide5_p(1000)
=================================================
def divide5_r(k):
for i in range(k):
if i%5==0 and i!=0:
return(i)
print(divide5_r(1000))