To view solutions, see the file exceptions-str-to-int.py
in your text editor.
Task:
Read a string, S
, and print its integer value; if S
cannot be converted to an integer, print Bad String
.
Note: You must use the String-to-Integer and exception handling constructs built into your submission language.
If you attempt to use loops/conditional statements, you will get a 0
score.
Input Format
A single string, S
.
Constraints
1 <= |S| <= 6
, where|S|
is the length of stringS
.S
is composed of either lowercase letters (a - z
) or decimal digits (0 - 9
).
Output Format
Print the parsed integer value of S
, or Bad String
if S
cannot be converted to an integer.
Sample Input
3
Sample Output
3
Sample Input
za
Sample Output
Bad String
Solution:
In exceptions-str-to-int.py
.
Return to navigation list