string - Closed Functions in Python -


I am trying to write a function bin_to_dec (s) which is a binary String takes number and converts it into decimal number / integer

I know that it has probably been made in the way of converting it but I'm trying to complete it through recurrence . In this way I have programmed so far

I am getting a memory error. How can I edit my last statement to make this work?

I would like to avoid recursion, which is not necessary for what you are trying to do. I had to go in some way with

  def binToDec (s): total = 0 for the index, value in enumerate (s [:: - 1]): total + = int (value) ) * 2 ** Index Returns Total & gt; & Gt; & Gt; BinToDec ('1100') 12   

The same idea to use a list comp:

  DIF bin TODDAC: return amount (int) * 2 ** index index, value in enumerate (s [:: - 1])   

If you want to continuously repeat this in fact

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -