Python 3.x 在另一个IDE中的HackerRank中的副本输入(升华文本或spyder)

Python 3.x 在另一个IDE中的HackerRank中的副本输入(升华文本或spyder),python-3.x,Python 3.x,我试图将黑客等级问题的输入复制到另一个IDE中。见鬼,汉克罗克本身根本不起作用。 请帮我回答以下问题: 如何访问HackerRank平台中的每一行 如何在诸如sublime text或spyder之类的IDE中复制输入 是我的代码不好吗 以下是输入: 12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print 这里有两个挑战。如何逐行迭代 我使用了以下代码

我试图将黑客等级问题的输入复制到另一个IDE中。见鬼,汉克罗克本身根本不起作用。

请帮我回答以下问题:

  • 如何访问HackerRank平台中的每一行
  • 如何在诸如sublime text或spyder之类的IDE中复制输入
  • 是我的代码不好吗
  • 以下是输入:

    12
    insert 0 5
    insert 1 10
    insert 0 6
    print
    remove 6
    append 9
    append 1
    sort
    print
    pop
    reverse
    print
    
    这里有两个挑战。如何逐行迭代 我使用了以下代码:

    test = []
    n = int(raw_input())
    for _ in range(0,int(raw_input())):
        input = raw_input.split(" ")
        if len(input) == 3:
            eval("test.{0}({1},{2})".format(input[0],input[1],input[2]))
            print(test)
        elif len(line2) == 2:
            eval("test.{0}({1})".format(input[0],input[1]))
            print(test)
        elif len(line2) == 1:
            eval("{1}(test)".format(input[0](test)))
            print(test)
    
    print(test)
    
    这里的目标是逐行迭代,并将每一行作为命令执行

    Consider a list (list = []). You can perform the following commands:
    
    insert i e: Insert integer  at position .
    print: Print the list.
    remove e: Delete the first occurrence of integer .
    append e: Insert integer  at the end of the list.
    sort: Sort the list.
    pop: Pop the last element from the list.
    reverse: Reverse the list.
    Initialize your list and read in the value of  followed by  lines of commands where each command will be of the  types listed above. Iterate through each command in order and perform the corresponding operation on your list.
    

    这是一个关于列表的非常好的问题。
    用这种方法可以解决这个问题

    N = int(input())
    result = []
    for n in range(N):
        x = input().split(" ")
        command = x[0]
        if command == 'append':
            result.append(int(x[1]))
        if command == 'print':
            print(result)
        if command == 'insert':
            result.insert(int(x[1]), int(x[2]))
        if command == 'reverse':
            result = result[::-1]
        if command == 'pop':
            result.pop()
        if command == 'sort':
            result = sorted(result)
        if command == 'remove':
            result.remove(int(x[1]))
    
    来回答您的问题
    在输入时,考虑值并相应地执行函数。 2-我给你的代码在任何地方都有效(升华、spyder等)。
    我有一些想法

    • 您正在为“N”获取输入,这就是为什么要在“for”循环中再次获取输入的操作数。您可以在那里使用“N”,避免混淆
    • 不必检查输入的长度,您可以编写提供的关键字,如“append”、“print”等,然后比较哪一个是正确的,然后采取相应的行动
    • “line2”未在“if”条件中的任何位置和相同位置定义,您正在使用“input”作为变量名
    我试着用最简单的词解释它。
    如果有帮助,请告诉我