作者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://webptt.com/cn.aspx?n=bbs/Python/M.1403838521.A.EBC.html
1F:→ alibuda174:print(''.join([chr(ord(i) + 2) for i in temp])) 06/27 11:27
2F:→ Quietlake:感谢教导,没想过可以合起来 06/27 17:14
3F:推 disap:似乎是凯萨密码? 06/28 21:24