File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ Aim: Read a string, S and print its integer value. If S cannot be converted to
3
+ an integer, print Bad String.
4
+
5
+ '''
6
+
7
+ # getting the input
8
+ S = input ().strip ()
9
+ try :
10
+ # if it's possible to convert the entered string into an integer then this block will execute
11
+ print (int (S ))
12
+ except :
13
+ # if it's not possible, then this block will be executed
14
+ print ('Bad String' )
15
+
16
+ '''
17
+
18
+ COMPLEXITY:
19
+
20
+ Time Complexity -> O(1)
21
+ Space Complexity -> O(1)
22
+
23
+ Sample Input 1:
24
+ 3
25
+ Sample Output 1:
26
+ 3
27
+ Sample Input 2:
28
+ SB
29
+ Sample Output 2:
30
+ Bad String
31
+
32
+ Explaination:
33
+ '3' as a string can be converted into the integer 3, whereas SB can't be
34
+ converted to an integer hence the 'except' block is executed and 'Bad String'
35
+ is printed.
36
+
37
+ '''
You can’t perform that action at this time.
0 commit comments