FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonCollection/dailyCodingTask/day088_division.py at master · marcelpetrick/pythonCollection · GitHub
marcelpetrick
/
pythonCollection
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonCollection
/
dailyCodingTask
/
day088_division.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (27 loc) · 1.06 KB
Breadcrumbs
pythonCollection
/
dailyCodingTask
/
day088_division.py
Copy path
File metadata and controls
35 lines (27 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This question was asked by ContextLogic.
#
# Implement division of two positive integers without using the division, multiplication, or modulus operators.
# Return the quotient as an integer, ignoring the remainder.
# ------------------------------------------------------------------------------
import
unittest
# ------------------------------------------------------------------------------
def
divide
(
a
,
b
):
if
b
==
0
:
return
None
quotient
=
0
while
a
>=
b
:
a
-=
b
quotient
+=
1
return
quotient
#------------------------------------------------------------------------------
class
Testcase
(
unittest
.
TestCase
):
def
test_divide
(
self
):
self
.
assertEqual
(
0
,
divide
(
0
,
3
))
self
.
assertEqual
(
2
,
divide
(
4
,
2
))
self
.
assertEqual
(
2
,
divide
(
5
,
2
))
self
.
assertEqual
(
3
,
divide
(
6
,
2
))
self
.
assertEqual
(
None
,
divide
(
5
,
0
))
#------------------------------------------------------------------------------
# ---- here comes the execution of the unit-tests ----
if
__name__
==
'__main__'
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL