Reputation: 11
I am facing issue in taking different test cases in python
If I am writing code to first test case the second test case not executed and if I am writing code to the second test case the first test case not executed.
I tried in c/c++14 the both test cases are taking perfectly without any error, but in python 3.7 it shows error
This is for test-case-1
s1=input()
s2=input()
This is for test-case-2
s1,s2=input().split()
How can I write code for both test cases to get satisfy
Upvotes: 0
Views: 280
Reputation: 61063
You can catch the error from trying to unpack too few elements, and ask for another input:
def get_inputs():
s1 = input()
try:
s1, s2 = s1.split()
except ValueError:
s2 = input()
return s1, s2
Upvotes: 2