我是靠谱客的博主 激动高跟鞋,最近开发中收集的这篇文章主要介绍python如何八进制转十进制,如何使用Python将八进制转换为十进制,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I have this little homework assignment and I needed to convert decimal to octal and then octal to decimal. I did the first part and can not figure out the second to save my life. The first part went like this:

decimal = int(input("Enter a decimal integer greater than 0: "))

print("Quotient Remainder Octal")

bstring = " "

while decimal > 0:

remainder = decimal % 8

decimal = decimal // 8

bstring = str(remainder) + bstring

print ("%5d%8d%12s" % (decimal, remainder, bstring))

print("The octal representation is", bstring)

I read how to convert it here: Octal to Decimal but have no clue how to turn it into code. Any help is appreciated. Thank you.

解决方案

From decimal to octal:

oct(42) # '052'

Octal to decimal

int('052', 8) # 42

If you want to return octal as a string then you might want to wrap it in str.

最后

以上就是激动高跟鞋为你收集整理的python如何八进制转十进制,如何使用Python将八进制转换为十进制的全部内容,希望文章能够帮你解决python如何八进制转十进制,如何使用Python将八进制转换为十进制所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部