Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 2.11 KB

File metadata and controls

51 lines (35 loc) · 2.11 KB

Python Strings Problems

Note: This will contain a mix of problems I have created with the problems on platform such as HackerRank. If you do not have an account, I would recommend making one. Do not get intimidated by the name Hackerrank. You are not doing any hacking (not yet!)

Also do not get intimidated by keywords such as def or concepts like loops and conditionals. If you are not familiar with those concepts, you can skip Problem 6 and 7, but give it a try!

  1. Write a Python program to count the number of times the letter 'a' is in a given string. If there is none, return zero. Here's how your program might look like:

    def count_a(input_string):
        # your code here
        return # count of the letter 'a' or 0
  2. What is wrong with the program below? List out all the problems you see!

name = 'Hello World"
is_python = ""
I am writing this to demonstrate nothing,
and test if you can figure out a problem, if there is one!
""
result = 'Ajay' + 27

# Hint, if you cannot find the problem, try running these in a python shell
  1. This is a Hackerrank Problem: What's Your Name?

  2. This is a Hackerrank Problem: String Split

  3. This is a Hackerrank Problem: Capitalize!

  4. Common Characters: Suppose you are given two strings as an input. You have to write a program to check how many characters are present in both of the strings.

    For example:
    input1 = "Coding"
    input2 = "Programming"
    
    Output = 4 (the only characters present in both inputs are 'o', 'i', 'n' 'g. Note that 'g' repeats two times in 'Programming'. You have to write the program in such a way that it ignores the repeatations)
    

    Your program might look like this:

    def count_repeat(string_1, string_2):
        # your code here
       	return # an integer or 0 if no common characters