Python: My Return statement always returns None -


this function able take in binary number string , convert decimal number. reason, function returns none , can not understand why happening. if provide me explanation appreciated.

total = 0 power = 0 def binarytodecimal(binarystring):     global total, power      n = len(binarystring) - 1      if n < 0:         return total     else:         if binarystring[n] == '1':         total += (2 ** power)     power += 1     binarytodecimal(binarystring[:-1]) 

the final line needs return binarytodecimal(binarystring[:-1]). @ moment you're returning total last call, none of preceding calls returning anything.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -