第一个python小程序,2进制转10进制

时间:2014-07-01 09:35:48   收藏:0   阅读:226


#Bin to Dec
#my first python programe
n = c = itm = 0
a = raw_input(‘please input Binary number:\n‘)
for n in range(0,len(a)):
   b = a[n:n+1]
#   print ‘n is‘, n
#   print ‘b is‘,b
#   print ‘len‘,len(a[n:])   
   if b == ‘1‘:   
c = 2**(len(a[n:])-1)
#print ‘c1 is‘,c
   else:
    c = 0
#    print ‘c is 0‘   
   itm = c + itm
#   print ‘itm = ‘,itm
print ‘From Bin To Dec is‘,itm


第一个python小程序,2进制转10进制,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!