pythonジョブ6コード(文字列の実際の応用)
19899 ワード
タスク1:暗号解読プログラム
タスク内容:
ミッション2:身分証明書の秘密
身分証明書番号の意味:
コード:
タスク3:テキスト文字統計プログラム
タスク内容:
コード:
実行結果:
タスク4:パスワード設定
タスク内容
コード:
タスク内容:
# ASCII+5
# ASCII-5
str='ixo678'
for i in str:
a=ord(i)-5
b=chr(a)
print(b,end="")
ミッション2:身分証明書の秘密
身分証明書番号の意味:
# :
# 1、2 : ( 、 ) ;
# 3、4 : ( ) ;
# 5、6 : ( 、 、 ) ;
# 7—14 : 、 、 ;
# 15、16 : ;
# 17 : , ;
# 18 , 。
# 0—9 , x 。 , 10, X 。
コード:
a=input(" :")
if(len(a)==18):#
address=a[0:4]# 1~4
if (int(address)==1301):
print(" ")
elif (int(address)==1302):
print(" ")
elif (int(address) == 1303):
print(" ")
elif (int(address) == 1304):
print(" ")
elif (int(address) == 1305):
print(" ")
elif (int(address) == 1306):
print(" ")
elif (int(address) == 1307):
print(" ")
elif (int(address) == 1308):
print(" ")
elif (int(address) == 1309):
print(" ")
elif (int(address) == 1310):
print(" ")
elif (int(address) == 1311):
print(" ")
birthday=a[6:14]# 7~14
year=int(birthday[0:4])
month=int(birthday[4:6])
day=int(birthday[6:8])
print(" %d %d %d "%(year,month,day))
sex=a[16]# 17 : , ;
if (int(sex)%2==0):
print(" ")
else:
print(" ")
else:
print(" ")
タスク3:テキスト文字統計プログラム
タスク内容:
:2020, ,china, !
コード:
str="2020, ,china, !"
b,c,d,e=0,0,0,0 # b ; c ; d ; e
# a~z:97~122; A~Z:65~90; 0~9:48~57; :33~47
for i in str:
a = ord(i)
if ((65 <= a and a <= 90) or (97 <= a and a <= 122)): #
b += 1
elif (48 <= a and a <= 57): #
d += 1
elif (33 <= a and a <= 47):#
e += 1
f=b+d+e
c=len(str)-f
print("'2020, ,china, !' %d ,%d ,%d ,%d "%(b,d,e,c))
実行結果:
'2020, ,china, !' 5 ,4 ,4 ,4
タスク4:パスワード設定
タスク内容
: ,
コード:
b,c,d=0,0,0
while True :
mima =input(" :")
if(len(mima)>=6):
for i in mima:
a = ord(i)
if (65 <= a and a<= 90):
b += 1
elif (48 <= a and a<= 57):
c += 1
elif (97 <= a and a<= 122):
d += 1
if(b!=0 and c!=0 and d!=0):
print(" ")
break
else:
print(" , , ")
continue
else:
print(" !")
continue