Day 16: Exceptions - String to Integer

Sort by

recency

|

1004 Discussions

|

  • + 0 comments

    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... 
    
  • + 0 comments

    HOW CAN I RECOVER A STOLEN BTC/USDT/ETH? HIRE FIXER WALLET RETRIEVAL Never took much time for me to be able to recover a stolen bitcoin worth of $124k. Reaching out to FIXER WALLET RETRIEVAL, one of the trusted and reputable hackers out here can save you the energy of becoming a stranded victim of crypto fraud. Here is how to contact these hackers; Email fixerwalletretrieval@fixer.co.site

  • + 0 comments

    Python 3 solution ** For the code to run remove the if main**

    S = input().strip()

    try: value = int(S) print(value) except ValueErr or: print("Bad String")

  • + 0 comments

    I did not know this is so simple

    int main() { string S;

    getline(cin, S);
     try {
        int integerValue = stoi(S); // Convert string to integer
        cout << integerValue << endl; // Print the integer value
    } catch (const invalid_argument&) {
        cout << "Bad String" << endl; // Handle conversion error
    } catch (const out_of_range&) {
        cout << "Bad String" << endl; // Handle range error
    }
    
    return 0;
    

    }

  • + 0 comments

    for code java public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String S = sc.nextLine(); try{ int num = Integer.parseInt(S);
    System.out.println(num); }catch(Exception e){ System.out.println("Bad String"); }

    }
    

    }