#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
原文地址:http://374721.blog.51cto.com/364721/1432643