[英]Is there a while(input()) loop in Python 3.x
我正在尝试编写一个 python 解决方案来解决 Kattis 上需要一个 while(input()) 循环的多少位数字我有一个 C++ 解决方案使用
int n;
while( cin >> n ) {}
但我想知道是否有办法在 python 3.x 中做到这一点
我通常这样编码:
try:
while True:
n = int(input())
...
except EOFError:
pass
一旦没有更多的输入要读取, input()
调用将抛出 EOFError 并退出循环。
你可以使用 for 循环而不是 while for in where var 是一个变量,iterable 是一个列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.