Q.1 Fizz Buzz

Watch Video on Youtube

    Given an integer n, return a string array answer (1-indexed) where:
    answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
    answer[i] == "Fizz" if i is divisible by 3.
    answer[i] == "Buzz" if i is divisible by 5.
    answer[i] == i (as a string) if none of the above conditions are true.
    Example 1:
    Input: n = 3
    Output: ["1","2","Fizz"]

    Example 2:
    Input: n = 5
    Output: ["1","2","Fizz","4","Buzz"]

    1. Python Code:
      
      def fizzBuzz(self, n: int) -> List[str]:
          l = []
          for i in range(1,n+1):
              if i%3 == 0 and i%5 == 0:
                  l.append("FizzBuzz")
              elif i % 3 == 0:
                  l.append("Fizz")
              elif i % 5 == 0:
                  l.append("Buzz")
              else:
                  l.append(str(i))
          return l   
          
                  


Q.2 Find Alphabets & Numbers

Watch Video on Youtube

    Write a python code to find numbers and alphabets from the given string and put it in one list.
    The list will have two elements – the first element is a type of string which contains the alphabet and the second element is a type of integer. The input string will not have any special characters. The input string can have either the combination of Alphabets and Numbers or only Alphabets or only Numbers or it can be an empty string.

    Define a function to build a logic which returns a list. This list will contains a string first followed by numbers (must be in an integer format).

    Cases to be handled:
    1. If the string contains alphabets and numbers both then the list will contain two
    elements. First will be a string and the second will be a number(s) [Alphabets, Numbers].
    2. If the string contains only alphabets then the list will contain only one element in the list [Alphabets].
    3. If the string contains only numbers then the list will contain only one element in the list [Numbers].
    4. If the string is empty, then it will return an empty list [].

    Refer to the instructions below and sample input-output for more clarity on the requirement.

    Instructions to write the main section of the code.
    You would be required to write the main section completely, hence follow the below
    instructions
    1. First read a string from the user.
    2. Next, call a function str_num_list(string) with string as an argument.
    3. str_num_list(string) function will separate the alphabet and numbers and return the list.
    4. Print the returned list from the str_num_list(string)
    You can use/refer the below given sample input and output to verify your solution.

    Sample Input:
    Hyper12345Lower100
    Sample Output:
    ['HyperLower', 12345100]

    1. Python Code:
      
      def str_num_list(s1):
          str_num = []  # initialize an empty list to hold the alpha and numeric values
          alpha = ''.join([i for i in s1 if i.isalpha()])  # extract all alphabetic characters from input string
          if len(alpha) != 0:
              str_num.append(alpha)  # if there are any alphabetic characters, append them to str_num list
          num = ''.join([i for i in s1 if i.isdigit()])  # extract all numeric characters from input string
          if len(num) != 0:
              str_num.append(int(num))  # if there are any numeric characters, convert them to an integer and append to str_num list
          return str_num  # return the list containing alphabetic and numeric values
      
      # get user input and pass it to the function
      inp_s = input()
      ans = str_num_list(inp_s)
      
      # print the output
      print(ans)