python - 如何自动更改字符串中的字符?
问题描述
我正在尝试制作一个加密程序。到目前为止,我只能更改顺序。我怎样才能让它改变一个角色到另一个角色?前任; 'n' => '&'、'a' => '*' 等
我试图制作一个变量数组来更改字符。
def convert():
print('This will re-order your password')
y = input('Your password? 13 letters, numbers & symbols: ')
l = y[0] + y[11] + y[10] + y[9] + y[8] + y[7] + y[6] + y[5] + y[4] +
y[3] + y[2] + y[1] + y[12]
print(l)
def original():
print('This will re-order your password to its original state')
z = input('Your muddled password? 13 letters, numbers & symbols: ')
t = z[0] + z[11] + z[10] + z[9] + z[8] + z[7] + z[6] + z[5] + z[4] +
z[3] + z[2] + z[1] + z[12]
print(t)
p = input('Convert or Convert to original? For \'Convert\', type \'c\' or
\'C\' and for \'Convert to original\', type \'o\' or \'O\': ')
if p == 'c' or 'C':
convert()
elif p == 'o' or 'O':
original()
else:
print('Invalid')
# Example Passwords:
# 6539HopPop
# And@457654321
解决方案
你不能尝试在字符串上替换方法,比如
password="Imback4u";
newpassword=password.replace(old char,new char)
多次更换使用
password.replace("value1", "").replace("value2", "text")
推荐阅读
- google-kubernetes-engine - 从 Dataproc 访问 Google Cloud Kubernetes 服务
- java - 如何解决以下存根是不必要的 - Mockito - Android
- angular - Angular 8 - 在订阅之前进行过滤,如果过滤器返回null,它会触发它吗?
- r - gganimate 沿时间序列,而不是从左到右
- c# - 锐器。如何添加 xaml 模板
- elixir - 为什么第二次挂载 LiveView 后 Highcharts 图表会消失?
- ios - 如何垂直居中字体字形?
- java - jackson ObjectMapper 可以转换类的静态和最终字段吗?
- xcode - Xcode连接手机后出现错误
- java - 我无法使用 java netbeans 存储数据本地主机(数据库)