【问题标题】:enter n numbers to control the enter of the map or array输入 n 个数字来控制地图或数组的输入
【发布时间】:2015-10-24 19:08:22
【问题描述】:

我希望用户输入 n 个数字以在数组或列表中打开它以对其进行限制示例 输入: 3 4 5 6 用户输入的 3 让他再输入 3 个号码以进行操作,我希望它在线 (4 5 6) 第二点 我想打印所有循环结果 示例:

n=int(raw_input('Enter The Number of Lines')) #number of lines to open string ex: 2
for x in range(n):
a=str(raw_input('Enter The String To revers')) #the string example ex: first line abc second def
for x in reversed(a):
         a
print a #i want to print all result in loop def and abc not def only
#i want it to print 
`#def`
#abc

【问题讨论】:

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


    【解决方案1】:

    据我了解,您正在努力存储并稍后检索您正在接受的输入。

    让我们看看线

    a=str(raw_input('Enter The String To revers'))
    

    在这里,您每次都将input 字符串分配给一个变量,但一个变量一次只能存储一个值。

    您可以做的是将所有值存储在一个列表中并在以后使用它们。如下:

    a=str(raw_input('Enter The String To revers'))
    lst.append(a) #adding input to a list in each iteration
    

    完整的解决方案可能如下所示:

    noOfline=int(raw_input('Enter The Number of Lines'))
    listOfInput=[] 
    for x in range(noOfline):
        inputString=str(raw_input('Enter The String To reverse'))
        listOfInput.append(inputString) 
    for value in listOfInput:
        print value[::-1]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 2019-02-13
      • 2022-08-14
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      相关资源
      最近更新 更多