ASCII碼轉換為int:ord('A') 65
int轉為ASCII碼:chr(65) 'A'
題目內容:
實現一個凱撒密碼的變種算法,對輸入字符串進行加解密處理
把字母a-z分別循環對應為相距13個位置的字母n-m,即
原文字母:a b c d e f g h i j k l m n o p q r s t u v w x y z
對應字母:n o p q r s t u v w x y z a b c d e f g h i j k l m
大寫字母對應方式與小寫字母類似,其他符號(含標點符號)不作處理
輸入格式:
一個英文字符串
輸出格式:
經過上述算法加密的字符串
輸入樣例:
The Zen of Python
輸出樣例:
Gur Mra bs Clguba
時間限制:2000ms內存限制:128000kb
題解:string類型無法被修改,若修改需要先轉為列表類型,最后再連接起來
str=input()strlist=list(str)for i in range(len(strlist)): if strlist[i]>='a' and strlist[i]<='z': if ord(strlist[i])+13<=122: strlist[i]=chr(ord(strlist[i])+13) else: strlist[i]=chr((ord(strlist[i])+13)%122+96) elif strlist[i]>='A' and strlist[i]<='Z': if ord(strlist[i])+13<=90: strlist[i]=chr(ord(strlist[i])+13) else: strlist[i]=chr((ord(strlist[i])+13)%90+64)print("".join(strlist))
以上這篇python中ASCII碼字符與int之間的轉換方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答