Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 8d70990

Browse files
committed
decimal to octal
1 parent 360bf39 commit 8d70990

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Decimal To octal
3+
4+
"""
5+
6+
7+
def decimal_to_binary(n):
8+
9+
temp = 1
10+
main = 0
11+
while (temp <= n):
12+
temp *= 8
13+
14+
temp //= 8
15+
16+
while (temp > 0):
17+
18+
lastdigit = n // temp
19+
n -= lastdigit * temp
20+
temp //= 8
21+
main = main * 10 + lastdigit
22+
23+
return main
24+
25+
26+
if __name__ == "__main__":
27+
28+
n = int(input("Entre number"))
29+
print(decimal_to_binary(n))

0 commit comments

Comments
 (0)