【问题标题】:How to run a statement again and again on a case but on different occurrences [duplicate]如何在一个案例上一次又一次地运行一个语句,但在不同的情况下[重复]
【发布时间】:2023-03-19 15:22:01
【问题描述】:

大家好,我正在制作一个编码系统,其中每个字母都被转换为预定义的乱码。 例如,'a' 已经被设置为 'ashgahsjahjs'。

但是使用if a in data: print("ashgahsjahjs")只会执行一次,如果单词中有多个A,它不会乱码打印。

使用 while 循环也不起作用,因为它会无限期地打印,所以有没有办法在每次出现新字母时打印乱码。

【问题讨论】:

    标签: python loops if-statement encoding cryptography


    【解决方案1】:

    你可以尝试索引字符串。

    your_string = "are you an apple?"
    for i in range(len(your_string)):
        if "a" == your_string[i]:
            print("Found a at position {pos}".format(pos=i))
        else:
            print("Nope")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2020-01-10
      相关资源
      最近更新 更多