Hehey!
I'm learning python on a website called codecademy.com, where I made a
program to decode binary numbers. I guess the site uses a different
compiler, because on the site my code worked fine, but when I copied and
pasted it into the Python IDLE (3.4.2) it didn't work! I'm really don't know
what is wrong with my code, can anyone of you fine sirs help me?
Meh code:
number_input = input("What binary number do you want me to decode? ")
def decoder(number):
number_backwards = str(number)[::-1] # Because binary numbers go from
right to left.
result = 0
value = 1
br = False
for n in number_backwards:
if n != "1" and n != "0":
print number, "is not a binary number"
br = True
break
elif n == "1":
result += value
value += value
if br == False:
print "The binary number decoded is", result
decoder(number_input)
Thank you! ^^
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor