0
Do u know how to work on multiple line inputs in python ?
For example , we don't know the count of input lines , and we have to calculate the sum of entered inputs . That's just one input with multiple lines .
7 Answers
+ 2
You can define an "exit sequence".
If the exit sequence is input, the loop stops.
If you are reading numbers you can take any value that can't be converted
+ 2
Saeed Hayati
Are you doing this in SoloLearn Playground or somewhere else (in IDE)?
+ 2
Abir Hasan I don't think that's what he meant. But exception handling like you did is probably the best approach.
Saeed Hayati you can do something like this
sum = 0
while True:
try:
sum += int(input())
except ValueError:
continue
except EOFError:
break
print(sum)
This code ignores input lines that can't be cast to integer (ValueError)
+ 1
Have you tried using exception handling yet?
0
It's not in the sololearn .
0
My problem is , I can't get more than one input , and the only input has multiple lines.
- 1
Did you mean like this?
https://code.sololearn.com/cbz1FZAOm4MU/?ref=app