python - 打印一行中的字母 + 1

标签 python

Problem:

You and your friends have created a secret code!

The secret code is hidden in many lines. It's the first letter of the first line, plus the second letter of the second line, and so on, like this:

Basically it's a secret Won't they find it? Who would be looking? Nah! It's fine. B + o + o + ! spells BOO!

Your program should work like this:

Line: Basically it's a secret


Line: Won't they find it?

Line: Who would be looking?

Line: Nah! It's fine.

Line: 

BOO! ​

Your program should read multiple lines of input, get the correct letter from each line. Then it should join each letter and print it in capitals.

到目前为止,我有这段代码,它获取输入,将每一行添加到列表中,然后当用户输入空格时停止。但我有点不确定如何获取它,因此打印第一行的第一个字母,打印第二行的第二个字母,打印第三行的第三个字母等等。

listo = []
line = input("Line: ")
while line:
  listo.append(line)
  line = input("Line: ")
print(test)
for i in listo:
  print(i[0+1])

最佳答案

这可能有效:

lines = [ '123', 'abc', 'def' ]
print ''.join( b[a] for a,b in enumerate(lines) ).upper()

打印:

1BF

关于python - 打印一行中的字母 + 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52022673/

相关文章:

python - 在特定字符串后获取多个数字

python - 使用 Python 读取 Turtle/N3 RDF 文件

python - 为什么 chr(0x24) + chr(0x84) 的结果在 python 2 和 3 中不同

python - 将两列组合在一起的新数据框

python - 根据不同文件夹中的名称重命名文件夹中的文件

python - Django - 以形式访问request.session

python - 缩短这些线的正确方法是什么

python - Python 扩展的正确名称是什么?

python - 动态定义sympy.abc变量: name error handling

python - 在 poke 游戏的技巧中迭代元组时更新 defaultdict