Py3 翻译问题+replace
发布日期:2021-05-07 23:17:47 浏览次数:23 分类:原创文章

本文共 879 字,大约阅读时间需要 2 分钟。

Powered by:AB_IN 局外人

一个翻译的水题,用套版就行了。

while True:    try:        n=int(input())        s=input()        import string as st        before=st.ascii_lowercase #返回一个字符串全是小写        after=before[n:]+before[:n]        table=str.maketrans(before,after) #为translate创一个映射表        print(s.translate(table))    except:        break
number=st.digits #返回一个字符串,全是数字

while True:    try:        s=input()        a=s.replace('/','//').replace('^','**')        print(eval(a))    except:        break

只是想记一下replace不会改变原有的字符串。返回一个字符串。
参数replace("被替换的子串","替换成的子串", 被替换不超过几次)

while True:    try:        s=input()        a=max(s)        for i in s:            print(i,end="")            if a==i:                print("(max)",end="")        print()    except:        break

replace

while True:    try:        s=input()        s=s.replace(max(s),max(s)+'(max)')        print(s)    except:        break

完结。

上一篇:Py3 字符串水题
下一篇:一维差分小总结

发表评论

最新留言

很好
[***.229.124.182]2025年04月02日 06时17分44秒