英文:
Octal to Decimal conversion of number
问题
import math
def octalToDecimal(octalNumber):
decimalNumber = 0
i = 0
while (math.floor(octalNumber) != 0):
rem = math.floor(octalNumber) % 10
octalNumber /= 10
decimalNumber += rem * 8**i
++i
print(decimalNumber)
octalToDecimal(123)
英文:
I want to convert an octal number into a decimal one. Why am I getting 6 as an output instead of 83?
import math
def octalToDecimal(octalNumber):
decimalNumber = 0
i = 0
while (math.floor(octalNumber) != 0):
rem = math.floor(octalNumber) % 10
octalNumber /= 10
decimalNumber += rem * 8**i
++i
print(decimalNumber)
octalToDecimal(123)
答案1
得分: 2
写成i += 1而不是++i,Python中没有++操作符。
英文:
write i+=1 instead of ++i,theres no such operator as ++ in python
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论