Created
May 27, 2011 08:26
-
-
Save gennad/994851 to your computer and use it in GitHub Desktop.
Деление
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Целочисленне деление без оператора "деление" | |
def div(a,b): | |
if a < b: | |
return 0 | |
elif a == b: | |
return 1 | |
counter = 1 | |
process = True | |
while (process): | |
if b * (counter + 1) <= a: | |
counter += 1 | |
else: | |
process = False | |
return counter | |
print div(50, 5) # 10 | |
print div(10, 5) # 2 | |
print div(10, 10) # 1 | |
print div(10, 9) # 1 | |
print div(8, 9) # 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment