当未指定输入数量时,python接受输入 [英] python take input when number of input is not specified

查看:88
本文介绍了当未指定输入数量时,python接受输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,正在尝试解决SPOJ中的问题,

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

在此问题中输入的数量(指定的最大值为10,无论如何1到10之间)未指定
,因此会出现NZEC错误

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

我尝试了以下操作:

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

但不起作用

在c中,我们可以使用EOF来确定这一点

in c we can use EOF to determine this

请帮助

推荐答案

已解决
使用

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

这篇关于当未指定输入数量时,python接受输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆