[Tutor] What is wrong with my code?
Antonia van der Leeuw
antonia.van.der.leeuw at hotmail.nl
Sun Mar 22 21:18:22 CET 2015
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! ^^
More information about the Tutor
mailing list