python - 自定义输入导致错误,而运行时中给出的相同输入在 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()
解决方案
推荐阅读
- junit5 - 如何使用 TestInstanceFactory 管理实例的生命周期?
- rider - 在 Rider 中打开 Visual Studio 2017 .Net Core 2.1 Api
- ios - 如何在表格中显示自定义页脚视图?
- javascript - 单击时强制保持焦点在锚点上
- java - javax.enterprise.context.ApplicationScoped 和 javax.inject.Named 有什么区别?
- jquery - ASP.NET MVC JQuery 验证未通过提交输入触发。单击
- ios - 尝试打印整个数组,但只有最后一个正在打印到 textview
- java - 在不使用 ORM 的情况下更新特定数据库表列的优雅替代方案
- ios - 在 UITableview 上滑动删除,无需确认
- xamarin - 当我导航到上一个屏幕时,选项卡会移到顶部。Android 中的键盘问题