Guest User

Untitled

a guest
Oct 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. ##Python 3.7.0
  2. import math;
  3.  
  4. userInput = int (input ( "put a binary number here: " ));
  5.  
  6. length = len ( str ( userInput ) );
  7.  
  8. base = [ pow ( 2 , length - i - 1 ) for i in range ( 0, length ) ];
  9.  
  10. print ( base );
  11. result = 0
  12. for j in range ( 0, length ):
  13. result = result + base[ j ] * ( userInput // ( 10**( length - j - 1 ) ) % 10 );
  14. print (result);
  15. input ();
Add Comment
Please, Sign In to add comment