September 8th, 2012, 02:12 AM
Help in a simple program
I've just started to learn programming, and the first language I learn is Python.
My mission was to write a program that convert a decimal number to binary.
I wrote it like this:
def binary (n):
if n==0 or n==1:
else: return str(binary(n/2))+"1"
and the result this:
the output is correct, but how can I change the program that it wil be without the word "none" in the middle of the number?
September 8th, 2012, 03:02 PM
When n is 0 or 1, your function doesn't return anything, which in Python is equivalent to returning None. str(None) is 'None', which is why you're seeing it in your output.
Next time, be sure to put code tags [code][/code] around your code. Python code listings are particularly useless without them.