PAT (Basic Level) Practice Python解法 1057 数零壹(进制转换)
sample = input()
cnt = 0
otp = 0
for i in sample:
if ord(i) in range(65,91):
otp = otp+ord(i)-64
cnt = cnt+1
elif ord(i) in range(97,123):
otp = otp+ord(i)-96
cnt = cnt + 1
new = str(bin(otp))[2:]#bin,oct,hex()转进制
c0 = c1 = 0
for i in new:
if i=='0':
c0 = c0+1
else:
c1 = c1+1
if cnt!=0:
print(c0,c1)
if cnt==0:
print('0 0')
#如果求和答案是0,此时输出本应是0 0,但因为有一个0,所以反而0的个数会输出成1从而坑点3报错。