PAT (Basic Level) Practice Python解法 1057 数零壹(进制转换)

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报错。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值