| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
a = input('enter your code:')  
x = input('enter trans') 
y = input('enter transted') 
 
if len(x) != len(y): 
    print('error! trans should as long as transted.') 
 
else: 
    table = str.maketrans(x, y) 
    a = a.translate(table) 
 
    print('your encrypted cord is:', a) 
 
o = 0 
 
for i in x: 
    if x.count(i) > 1: 
        o = 1 
        continue 
 
for j in y: 
    if y.count(j) > 1: 
        o = 1 
        continue 
 
if o != 0: 
    print('trans or transted code conflict, unable to decrypt.') 
 
请问 28回动手1题字符加密 我的代码比答案还短一点点 会有啥问题不  功能倒是实现了 如图 
 
进来看的都感谢你们
你好,根据你提供的代码以及截图,我看到你的代码逻辑是正确的,实现了字符加密的功能。但是这种代码长度的缩短是以一些牺牲为代价的,比如没有添加必要的代码注释、错误处理等。此外,并不是所有的代码都可以通过缩减行数来实现更好的效果,因为代码的可读性也是非常重要的。 
另外,在代码中,你使用了“continue”语句,这样程序会跳过当前循环并继续执行下一个循环,但是在这个特定的场景中,使用“break”语句更加合适,因为只要有一个字符出现了多次,代码就无法进行解密操作。 
总之,如果你能够保证代码的逻辑正确且代码具有必要的注释和错误处理,那么缩减代码行数是没有问题的。 
 
 
 |   
 
 
 
 |