Day 16: Exceptions - String to Integer

Sort by

recency

|

1008 Discussions

|

  • + 0 comments

    I had to remove the "if name == 'main':"

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    S = input()
    try: 
        value = int(S) 
        print(value) 
    except ValueError: 
        print("Bad String")
    
  • + 1 comment

    !/bin/python3

    import math import os import random import re import sys if name == 'main': try: S = input() result = int(S) print(result) except ValueError: print("Bad String") except Exception: print("Bad String")

  • + 0 comments

    I've try many times. The compiler / Interperter is facing an issue. Please review it!

  • + 0 comments

    this is java 7 simple code import java.io.; import java.util.;

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        String S = bufferedReader.readLine();
    
        try {
            int parsedInt = Integer.parseInt(S);
            System.out.println(parsedInt);
        } catch (NumberFormatException e) {
            System.out.println("Bad String");
        } finally {
            bufferedReader.close();
        }
    }
    

    }

  • + 1 comment

    S = input().strip() try: print(int(S)) except ValueError: print("Bad String")

    isn't this a correct code... it is not working in any python versions... pls someone help na...