1

I am trying to write a python solution to How many digits on Kattis which requires a while(input()) loop I have a C++ solution using

int n;
while( cin >> n ) {}

but I was wondering if there was a way to do this in python 3.x

eyllanesc
  • 190,383
  • 15
  • 87
  • 142

2 Answers2

0

I usually code it like this:

try:
    while True:
        n = int(input())
        ...
except EOFError:
    pass

Once there is no more input to read, the input() call will throw an EOFError and exit the loop.

BarrensZeppelin
  • 315
  • 1
  • 6
  • 13
0

You can use a for loop instead of a while for in where var is a variable and iterable is a list

Daniel
  • 1