首页 > 解决方案 > 自定义输入导致错误,而运行时中给出的相同输入在 Python 中有效

问题描述

在以下代码中,如果输入以文本形式给出,则显示

Traceback (most recent call last):
  File "Main.py", line 6, in <module>
    u,v=map(int,input().split(" "))
ValueError: invalid literal for int() with base 10: ''

但是对于运行时中给出的相同输入,代码可以工作。

请帮我找出错误。谢谢你。

Input:
14 12
0 1
0 4 
0 2
1 3
1 4
3 5
5 6
5 7
6 8
2 11
11 10
9 13

node, edge = map(int, input().split(" "))

adjList = [[] for i in range(node + 1)]

for i in range(edge):
    u, v = map(int, input().split(" "))
    adjList[u].append(v)
    adjList[v].append(u)

print("Adjacency list unweighted:")

for i in range(edge):
    print(i, " ---> ", end=" ")
    for j in range(len(adjList[i])):
        print(adjList[i][j], end=" ")
    print()

标签: python

解决方案


推荐阅读