如何在没有.append()的情况下继续添加到数组?

2024-09-22 16:34:03 发布

您现在位置:Python中文网/ 问答频道 /正文

长话短说,我正在编写一个程序来解码隐藏在音频文件中的消息,我遇到了一个问题,我需要在数组或字符串中存储一个“提取的”ASCII字母,以便打印完整的消息。我现在的代码只给出了“消息”中的最后一个字母

def decode(sound):

  for sample in getSamples (sound):
      ampValue = getSampleValue (sample)
      asciiNum = ampValue % 128


      if asciiNum == 0:
        break

      asciiLet = chr (asciiNum)


  showInformation (asciiLet)

如何让我的代码显示隐藏在屏蔽音频中的所有字母?而且,我必须在不导入任何模块的情况下执行此操作


Tags: sample字符串代码程序消息def字母ascii
1条回答
网友
1楼 · 发布于 2024-09-22 16:34:03
youre getting the last letter because it always replaced the  variable 'asciiLet' every loop. try to create an inital value then add it. 

def decode(sound):
  asciiLet = '' #< - inital
  for sample in getSamples (sound):
      ampValue = getSampleValue (sample)
      asciiNum = ampValue % 128


      if asciiNum == 0:
        break

      asciiLet += chr (asciiNum)  #< - add it 


  showInformation (asciiLet)

相关问题 更多 >