string - Closed Functions in Python -
I am trying to write a function 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 The same idea to use a list comp: If you want to continuously repeat this in fact bin_to_dec (s) which is a binary String takes number and converts it into decimal number / integer
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
DIF bin TODDAC: return amount (int) * 2 ** index index, value in enumerate (s [:: - 1])
Comments
Post a Comment