代码拉取完成,页面将自动刷新
# Python3 program to divide a number
# by other without using / operator
# Function to find division without
# using '/' operator
def division(num1, num2):
if (num1 == 0): return 0
if (num2 == 0): return INT_MAX
negResult = 0
# Handling negative numbers
if (num1 < 0):
num1 = - num1
if (num2 < 0):
num2 = - num2
else:
negResult = true
# If num2 is negative, make it positive
elif (num2 < 0):
num2 = - num2
negResult = true
# if num1 is greater than equal to num2
# subtract num2 from num1 and increase
# quotient by one.
quotient = 0
while (num1 >= num2):
num1 = num1 - num2
quotient += 1
# checking if neg equals to 1 then
# making quotient negative
if (negResult):
quotient = - quotient
return quotient
# Driver program
num1 = 13; num2 = 2
# Pass num1, num2 as arguments to function division
print(division(num1, num2))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。