《python语言程序设计》2018版第8章第7题编写程序提示用户输入一个字符串然后显示字符串中的字母数

请添加图片描述


def get_number(uppercase_letter):
    tt = uppercase_letter.lower()
    number_text = ""
    if tt == '1':
        number_text = '1'
    elif tt == '2' or tt == 'a' or tt == 'b' or tt == 'c':
        number_text = "2"
    elif tt == '3' or tt == 'd' or tt == 'e' or tt == 'f':
        number_text = "3"
    elif tt == '4' or tt == 'g' or tt == 'h' or tt == 'i':
        number_text = "4"
    elif tt == '5' or tt == 'j' or tt == 'k' or tt == 'l':
        number_text = "5"
    elif tt == '6' or tt == 'm' or tt == 'n' or tt == 'o':
        number_text = "6"
    elif tt == '7' or tt == 'p' or tt == 'q' or tt == 'r' or tt == 's':
        number_text = "7"
    elif tt == '8' or tt == 't' or tt == 'u' or tt == 'v':
        number_text = "8"
    elif tt == '9' or tt == 'w' or tt == 'x' or tt == 'y' or tt == 'z':
        number_text = "9"
    elif tt == '0' or tt == '':
        number_text = '0'
    elif tt == '-':
        number_text ='-'
    return number_text


# number_t= input('Enter a string: ')
number_t = "1-800-Flowers"
distance_text = len(number_t)
for i in range(0, distance_text):
    a = get_number(number_t[i])
    print(f"{a}", end='')
print()
print(len(number_t))

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

电饭叔

谢谢各位兄弟们的关注,谢谢破费

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值