【发布时间】:2020-01-27 05:15:22
【问题描述】:
我编写了一个将整数转换为十六进制的代码。这是学校的作业。我写了很多,后来我的一个朋友给我看了他的代码,代码要短得多,这就是为什么我想知道我在哪里过度复杂的东西,以及我可以在哪里削减东西。 顺便说一句,我已经学习了 2 个月了,所以请放轻松:)!
我检查了我的代码,但找不到任何可以删除或简化的内容。
def Exponent2(): # which exponent I need to
devide with
global Exponent
Exponent = 0
while True:
a = dezimal // 16**Exponent
Exponent = Exponent + 1
if a == 0:
Exponent = Exponent - 1
break
Exponent2()
Ergebnis = ''
Dezimal2 = dezimal
while Dezimal2 != 0:
dezimal = Dezimal2 // 16**Exponent
Dezimal2 = Dezimal2 % 16**Exponent
CheckReverse()
Ergebnis = Ergebnis + str(dezimal)
Exponent = Exponent - 1
Länge = len(Ergebnis)
Ergebnis = Ergebnis[1:Länge]
print(Ergebnis)
【问题讨论】: