Safe Conversion
Completed
Read n lines. For each, print the number doubled if it is an integer, otherwise invalid: TEXT.
Input
Line 1: n. Then n lines.
Output
n lines.
Example
Input
4 5 abc -3 1.5
Output
10 invalid: abc -6 invalid: 1.5
Editor
Python
Hints
int("abc") raises ValueError.
Put the risky call inside try: and handle it in except ValueError:.
Solution explanation
Catch the specific exception you expect, not every possible error.
Show solution
for _ in range(int(input())):
text = input()
try:
print(int(text) * 2)
except ValueError:
print(f"invalid: {text}")