Skip to main content

EXCEPTIONS-Strings to Integers

EXCEPTIONS: 


Strings to Integers


Problem Statement

https://www.hackerrank.com/challenges/30-exceptions-string-to-integer/problem?h_r=email&unlock_token=4c8de9e311812f8c539f260bb3a52fc83df8b106&utm_campaign=30_days_of_code_continuous&utm_medium=email&utm_source=daily_reminder


Code in Python:

#!/bin/python3

import sys


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





______________________________________________________________________________

Please Like, Comment and Share!😉

Comments

Popular posts from this blog

Fibonacci Pattern/Series C program

C Program to print fibonacci pattern till N Input: 5 (N value) Output: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Solution:   #include <stdio.h> int Fibonacci(int num){     if(num<=1)         return num;     else     return Fibonacci(num-1)+Fibonacci(num-2) ;//2,1 } int main() { int n,f=1;     scanf("%d",&n);     for(int row=1;row<=n;row++,printf("\n")){         for(int col=1;col<=row;col++){             printf("%d\t",Fibonacci(f++));         }     }     return 0; } ___________________________________________________________ Please Like, Comment and Share! 😉

Leetcode Solutions (Array101) in C++

Max Consecutive Ones Given a binary array  nums , return  the maximum number of consecutive  1 's in the array . Example1: Input: nums=[1,1,0,1,1,1] Output: 3 Explanation:   The first two digits or the last three digits are consecutive 1s.  The maximum number of consecutive 1s is 3. Example2: Input: nums=[1,0,1,1,0,1] Output: 2 Constraints: 1 <= nums.length <= 10 5 nums[i]  is either  0  or  1 . CPP Code:     int findMaxConsecutiveOnes(vector<int>& nums) {         int max=0,count=0;         for (int x: nums)         {             if(x==1){                 count++;                 if(count>max)                     max=count;             }         ...

Removing Odd numbers from a linked list

Deleting odd numbers from a linked list in python: In this program, we will see  how to remove odd numbers from a linked list in Python. This is a very interesting program where we will learn how to remove odd numbers from a linked list. This contains a very easy to understand method of making a linked list. So when you know how to use the linked list we will learn how to remove odd numbers from it. (Note that the program done here is done without using recursion for further simplicity). For removing odd number we first find out the position of the “ head “.  The head is the starting node in a linked list.   Source Code:   class Node:     def __init__(self,data=None,next=None):         self.data=data         self.next=next class SingleLinkedList:          def __init__(self):         self.head=None           def print_list(self):   ...