1.判断火车票座位 #2438
###########有问题
def seat_numbers(seat): # 判定座位是否合法
if not(seat[:-1].isdigit()):# 万一输入是 2c1c排除
return False
if 1 <= int(seat[:-1]) <= 17 and seat[-1] in 'ABCDF':
return True
else:
return False
def window_or_aisle(seat): # 判定是窗口、过道还是中间
if seat[-1] in 'AF':
return '窗口'
elif seat[-1] in 'CD':
return '过道'
elif seat[-1] == 'B':
return '中间'
if __name__ == '__main__':
Seat = input().upper()
if seat_numbers(Seat):
print(window_or_aisle(Seat))
else:
print('输入错误')
2.统计单词的数量 #95
a = list(input().strip().split())
print(len(a))
3.凯撒密码——加密 #117092
import string
def caesar_cipher(text):
"""接收一个字符串为参数,采用字母表和数字中后面第3个字符代替当前字符的方法
对字符串中的字母和数字进行替换,实现加密效果,返回值为加密的字符串。
例如:2019 abc 替换为5342 def """
lowers = string.ascii_lowercase
#lowers是全部的小写英文字母
tolow = lowers[3:]
tolow+=lowers[0:3]
uppers = string.ascii_uppercase
toupp = uppers[3:]
toupp+=uppers[0:3]
#uppers是全部的大写英文字母
digits = string.digits #digits是全部的数字字符
todig = digits[3:]
todig += digits[0:3]
table = str.maketrans(lowers+uppers+digits,tolow+toupp+todig)
ans = text.translate(table)
return ans
if __name__ == '__main__':
plaintext = input()
print(caesar_cipher(plaintext))
4.汽车限行 #217427
import string
def verify(car_ID): #判断车牌号car_ID是否合法
if car_ID[0:3]!='鄂A-':
return False
elif len(car_ID)!=8:
return False
elif 'O' in car_ID or 'I' in car_ID:
return False
ls = [x for x in car_ID[3:] if x.isalpha()]
if len(ls)>2:
return False
return True
car = input()
if verify(car):
#####
if car[-1].isdigit():
if int(car[-1])%2==0:
print('双号通行')
elif int(car[-1])%2==1:
print('单号通行')
elif car[-2].isdigit():
if int(car[-2])%2==0:
print('双号通行')
elif int(car[-2])%2==1:
print('单号通行')
elif car[-3].isdigit():
if int(car[-3])%2==0:
print('双号通行')
elif int(car[-3])%2==1:
print('单号通行')
else:
#####
print('Data Error!')
5.缩写月份单词 # 1790
a = input()
month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
low_lst = [x.lower() for x in month_lst]
b = a.lower()
if b not in low_lst:
print('spelling mistake')
else:
if b == 'september':
print('Sept.')
else:
print(b.capitalize()[0:3]+'.')
# index = low_lst.index(b)
# print(month_lst[index][0:3]+'.')
6字符串移位# 71701
# 需要注意s为空的情况,len(s)=0,取模运算会报错
s = input()
n = int(input())
if n==0 or s=='':
print(s)
else:
if n>0:
n = n%len(s) # 取模
print(s[len(s)-n:]+s[0:len(s)-n])
else:
n = -n
n = n%len(s)
print(s[n:]+s[0:n])
7.个人信息提取(字符串)#63922
a = list(input().split())
print(f'姓名:{a[1]}')
print(f'班级:{a[2]}')
print(f'出生:{a[4][0:4]}年')
8. 字母查找2.0(函数)#76334
########注意replace来消除字符串的指定单个字符
def f(m,n):
#定义函数体完成题目要求功能
for i in m:
if i in n:
n=n.replace(i,'',1)
else:
return 'NOT FOUND'
return 'FOUND'
m=input()
if m.isalpha(): #完成该条件分支,输入字符串n判断单词m是否可以由n中的某些字符组成
####
n = input()
print(f(m,n))
else:
print('ERROR')