return m / n if m % n != 0 else m // n def myDiv(m,n):
if m//n == m/n:
return m//n
else:
return m/n def myDiv(m,n):
if m%n == 0:
return int(m/n)
else:
return m/n
print(myDiv(3,2))
print(myDiv(4,2))
# 今天这道题好像不难。 def mydiv(m,n)
if (m%n==0)return m//n
else return m/n Elastcio 发表于 2017-11-19 16:34
第9行 return round(result) 以四舍五入来取整,还不如return int(result)更有效率。 def myDiv(m,n):
result=m/n
if result==int(result):
return int(result)
else:
return result
print('myDiv(3,2)')
print(myDiv(3,2))
print('myDiv(4,2)')
print(myDiv(4,2))
def myDiv(m, n):
return m/n if m%n else round(m/n)
print(myDiv(3, 2))
print(myDiv(9, 4)) def myDiv(m, n):
x = m / n
if m % n == 0:
return int(x)
else:
return float(x)
c = myDiv(12, 3)
print(c) 本帖最后由 永恒的蓝色梦想 于 2019-9-22 12:41 编辑
def mydiv(a,b):return a/b if a%b else a//b def myDiv(m, n):
if m % n == 0:
return m // n
return m / n
a1, b1 = 3, 2
a2, b2 = 4, 2
print(myDiv(a1, b1))
print(myDiv(a2, b2))
页:
1
[2]