球求大佬帮我看看这个密码转换的代码为什么遇见r会出错
x = input("输入明文")y = int(input("后移位数"))
end=[]
base_big = ord("A")
base_little =ord("a")
for i in x:
if i ==" ":
end.append(" ")
if i.isupper():
end.append(chr((ord(i)-base_big+y)%26+base_big))
else:
end.append(chr((ord(i)-base_little+y)%26+base_little))
print (''.join(end)) s = input("输入明文:")
n = int(input("后移位数:"))
p = ''
for c in s:
if c . isalpha():
d = ord('A') if c . isupper() else ord('a')
x = ord(c) - d
p += chr(d + (x + n) % 26)
else:
p += c
print('密文为:' , p)
q = ''
for c in p:
if c . isalpha():
d = ord('A') if c . isupper() else ord('a')
x = ord(c) - d
q += chr(d + (x + 26 - n) % 26)
else:
q += c
print('原文为:' , q) 运行正常的:
#coding:gbk
x = input("输入明文:")
y = int(input("后移位数:"))
end=[]
base_big = ord("A")
base_little =ord("a")
for i in x:
if i ==" ":
end.append(" ")
if i.isupper():
end.append(chr((ord(i)-base_big+y)%26+base_big))
else:
end.append(chr((ord(i)-base_little+y)%26+base_little))
print (''.join(end))
运行结果:
输入明文:rRrRrRst
后移位数:1
sSsSsStu 没理由出错啊
报错信息来一下 请说明你的问题
互助团队的成员会帮你的。我也会
页:
[1]