Day 16: Exceptions - String to Integer

  • + 0 comments

    i dont know why my answer is wrong the output ic correct-#!/bin/python3

    import sys

    if name == 'main': S = input().strip() # Read input and strip leading/trailing whitespaces

    try:
        # Try to convert the string to an integer
        print(int(S))
    except ValueError:
        # If it fails, print "Bad String"
        print("Bad String")