以10为底的int()的无效文字:“ 1 2 3”

时间:2019-06-22 16:06:10

标签: python-3.x

我正在尝试使用for循环从列表中的用户那里获取输入并打印元素

我的代码:-

def myfunc():
    T = int(input())
    N = int(input())
    list=[]
    for i in range(0, T):
        for j in range(0, N):
            ele = int(input())
            list.append(int(ele))

    print(list)

    # for k in range(N):
    #     if list[k] > list[k+1]:
    #         return list[k+1]
    #     else:
    #         return -1

myfunc()

执行后出现此错误:-

Error:
File "main.py", line 18, in <module>                                                                                              
    myfunc()                                                                                                                        
  File "main.py", line 7, in myfunc                                                                                                 
    ele = int(input())                                                                                                              
ValueError: invalid literal for int() with base 10: '1 2 3' 

0 个答案:

没有答案