作者Quietlake (ekalteiuQ)
看板Python
標題[討論] 字母平移的程式改進
時間Fri Jun 27 11:08:36 2014
大家好,一直以來我寫程式就是想辦法得到答案,可是都不清楚如何改進,
因為自己懂的東西總是很少,所以想到說把自己的方法po上來,來看大家
有沒有些不同的想法,不知道這種文是否可以po,有問題請告訴我,我會改進。
--------------------------------------------------------------------
題目:將一個字串的字母上移2個
範例:輸入為abc時,輸出為cde
code:
temp = input("Enter a string: ")
i = len(temp)
temp = list(temp)
j = 0
while(j<i):
temp[j] = chr(ord(temp[j]) + 2)
j += 1
temp = ''.join(temp)
print(temp)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.241.1
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1403838521.A.EBC.html
→ alibuda174:print(''.join([chr(ord(i) + 2) for i in temp])) 06/27 11:27
→ Quietlake:感謝教導,沒想過可以合起來 06/27 17:14
推 disap:似乎是凱薩密碼? 06/28 21:24