We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 16: Exceptions - String to Integer
Day 16: Exceptions - String to Integer
+ 0 comments Python
try: print(int(input())) except ValueError: print('Bad String')
+ 0 comments python solution first remove if name == 'main': make sure the indentation write the following code S = input() result = '' try: S = int(S) result = S except Exception as e: result = 'Bad String' finally: print(result)
+ 0 comments
+ 0 comments c++
int main() { string S; getline(cin, S); try{ cout<<stoi(S); } catch(exception e){ cout<<"Bad String"; } return 0; }
+ 0 comments `if name == 'main': S = input()
try: print(f'{int(S)}') except ValueError as ve: print(f'Bad String')`
Load more conversations
Sort 924 Discussions, By:
Please Login in order to post a comment