+ Reply Thread
#1
My main aim is to preach the gospel of how simple and readable Python is and its learning steep is so friendly.
Python has built-in functions to convert from base 10 which is decimal to binary bin(), hexadecimal hex(), etc though they have to be integers, am still intermediate and decided to write a general code that will convert from denary to any base up to hexadecimal.
If you read the code well you'll notice it is like reading a novel. The default is binary.

def dec2any(value, conv = 2): Tmp = [] while value: if value < 0: break x = value//conv y = value%conv if y == 10: Tmp.append('A') elif y == 11: Tmp.append('B') elif y == 12: Tmp.append('C') elif y == 13: Tmp.append('D') elif y == 14: Tmp.append('E') elif y == 15: Tmp.append('F') else: Tmp.append(y) value = x Tmp.reverse() print(Tmp) [code/] Actually it prints out as a list. The indentation was messed up but I will attach the text file here[code]
def dec2any(value, conv = 2):
Tmp = []
while value:
if value < 0: break
x = value//conv
y = value%conv
if y == 10: Tmp.append('A')
elif y == 11: Tmp.append('B')
elif y == 12: Tmp.append('C')
elif y == 13: Tmp.append('D')
elif y == 14: Tmp.append('E')
elif y == 15: Tmp.append('F')
else: Tmp.append(y)
value = x
Tmp.reverse()
print(Tmp)
[code/]
Actually it prints out as a list.
The indentation was messed up but I will attach the text file here
#2

This is a very interesting one, I will test this out and see.

#3
dhtml wrote:

This is a very interesting one, I will test this out and see.


Yea
#4
mista_cee wrote:
dhtml wrote:

This is a very interesting one, I will test this out and see.


Yea


I really want to know more about python The syntax is lovely
Back to top