PAT (Basic Level) Practice 1033 旧键盘打字 Python

PAT (Basic Level) Practice 1033 旧键盘打字 Python_第1张图片

根据题意,这道题让我们根据要求去除第二行输入的字符串中的部分内容

1.判断上档键是否损坏,以进行下一步处理

2.根据要求去除字符串中特定字符

3.sys模块:可用于大量输入的加速

4.operator:可用于运算时的加速

代码如下:

import sys
import operator
in_1=sys.stdin.readline()
in_2=sys.stdin.readline()
out_1=""
upper_str = in_1.upper()
lower_str = in_1.lower()
str_1 = "_,-.0123456789abcdefghijklmnopqrstuvwxyz"
if '+' in in_1:
    for i in in_2:
        if i not in lower_str:
            if operator.lt(i,'A') or operator.gt(i,'Z'):
                if i in str_1:
                    out_1=out_1+i
else :
    for i in in_2:
        if i not in upper_str and i not in lower_str:
            out_1=out_1+i
print(out_1)

运行结果:

PAT (Basic Level) Practice 1033 旧键盘打字 Python_第2张图片

你可能感兴趣的:(PAT考试练习Python,python)