Day 16: Exceptions - String to Integer

  • + 18 comments

    Python 3

    #!/bin/python3
    import sys
    
    S = input().strip()
    
    try:
        line = int(S)
    except ValueError:
        print("Bad String")
    else:
        print(line)
    

    ERROR: You should use exception handling concepts.

    #!/bin/python3
    import sys
    
    S = input().strip()
    
    try: 
        print (int(S))
    except ValueError: 
        print ("Bad String")
    

    All ok. LOL