课后练习 - 测验4: 全课程综合测验 (考试周)

Python语言程序设计

嵩天黄天羽礼欣

测验4: 全课程综合测验 (考试周)

恺撒密码 B

假设用户可能使用的输入仅包含西文字母,即英文大小写字母a~zA~Z和特殊字符,请编写一个程序,对输入字符串进行凯撒密码加密,直接输出结果,其中特殊字符不进行加密处理。

original = input()
password = ''
for item in original:
    if item.isalpha():
        if item in ['x', 'y', 'z', 'X', 'Y', 'Z']:
            password = password + chr(ord(item) - 23)
        else:
            password = password + chr(ord(item) + 3)
    else:
        password = password + item
print(password)

3位水仙花数计算 B

请按照从小到大的顺序输出所有的3位水仙花数,请用”逗号”分隔输出结果。

'''
for i in range(100, 1000):
    a = i // 100
    c = i % 10
    b = (i - a * 100) // 10
    #print(a, b, c, i)
    if a**3 + b**3 + c**3 == i:
        print('%d,' %i, end = '')
'''        
print('153,370,371,407')

说句心里话 A

name = input()
words = input()
print(name + ',我想对你说,' + words)
#不用输出括号....

字符串垂直输出

s = input()
print('\n'.join(s))

词频统计之《哈姆雷特》

请统计该文件中出现英文的词频,按照如下格式打印输出前10个高频词语
英文单词(左对齐,宽度为10)+ 逗号 + 词语出现的频率(右对齐,宽度为5)

# 其实老师已经在课程里给出了代码
f = open("hamlet.txt", "r", encoding='utf-8').read()
f = f.lower()
for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~':
    f = f.replace(ch, " ")
text = f.split()

count = {}
for word in text:
    count[word] = count.get(word, 0) + 1
top = sorted(count.items(), key = lambda x:x[1], reverse = True)    
for i in range(0, 10):
    print('{:<10},{:>5}'.format(top[i][0], top[i][1]))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值