-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise31.py
More file actions
49 lines (40 loc) · 953 Bytes
/
Copy pathExercise31.py
File metadata and controls
49 lines (40 loc) · 953 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def convertIntToStr(integerNum: int) -> str:
"""
Convert Integer Number to String
:param integerNum: Number in integer
:type integerNum: int
:raise TypeError: If integerNum is not an int
:return: str
:rtype: str
"""
if integerNum == 0:
return "0"
DIGITS_INT_TO_STR = {
0: "0",
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7",
8: "8",
9: "9",
}
if integerNum < 0:
isNegative = True
integerNum = -integerNum
else:
isNegative = False
stringNum = ""
while integerNum > 0:
onesPlaceDigit = integerNum % 10
stringNum = DIGITS_INT_TO_STR[onesPlaceDigit] + stringNum
integerNum //= 10
if isNegative:
return "-" + stringNum
else:
return stringNum
...
for i in range(-10000, 10000):
assert convertIntToStr(i) == str(i)