python take input when number of input is not specified

此生再无相见时 提交于 2019-12-25 17:25:24

问题


I am new to python and trying to solve a problem in SPOJ ,

In this question number of input(maximum 10 is specified, how ever it could be anything between 1 to 10) is not specified hence it gives NZEC error

I tried this:

t = 10
while(t>0):
   t = t - 1 
   n = raw_input()
   if(len(n) == 0):
      break

but it does not work

in c we can use EOF to determine this

please help


回答1:


Solved Use

try:
   while True:
       n = int(raw_input())
       #do something
except:
   pass


来源:https://stackoverflow.com/questions/38621513/python-take-input-when-number-of-input-is-not-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!