Python Day 16: Exceptions - String to Integer




Read a string, S, and print its integer value; if S cannot be converted to an integer, print Bad String.



  1. #!/bin/python3
  2. import sys
  3. S = input().strip()
  4. try:
  5. print (int(S))
  6. except ValueError:
  7. print ("Bad String")




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube