【问题标题】:how to take user input where each input is given in new line in python如何在python的新行中给出每个输入的用户输入
【发布时间】:2017-05-20 18:20:54
【问题描述】:

假设用户在不同的行上提供输入,并且每行应该以不同的方式处理。例如,如果我想计算每个用户给定输入的字符数。就像,如果用户在不同的行上输入:

this is first line
this is second line
this is third line

如何将每一行作为新输入并将其存储在某处,然后对每个输入进行一些操作(计数字符数)。

【问题讨论】:

  • 您似乎错过了tutorial。请仔细阅读,这里无需赘述。

标签: python python-2.7 python-3.x


【解决方案1】:
inputs = [raw_input("enter input data\n") for _ in range(no_of inputs)]
for line in inputs:
   print(len(line))

试试上面的代码sn-p,希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    相关资源
    最近更新 更多