Answer to Question #262037 in Python for Isabel Cortez

Question #262037

1. Finding Letters

by CodeChum Admin


Instructions:

  1. Create two variables and assign them to an input() function. The first variable shall accept a single letter and the second variable shall store the inputted string.
  2. Using loops, count the number of times that the single letter appears on the inputted string, and when it appears at least twice in the string, print "Cody is really awesome"; else, print "Cody rocks".
  3. Tip: to make your code more efficient, use the break keyword to terminate the loop whenever the count of appearance of the single letter has already reached 2.



Input

The first line contains a single-letter string.

The second line contains a string.

e
CodeChum is awesome

Output

A line containing a string.

Cody is really awesome





1
Expert's answer
2021-11-06T11:47:53-0400
# Python program to count occurrences
# of a given character
 
# Method that return count of the 
# given character in the string

def count(s, c) :


     

    # Count variable


    res = 0


     

    for i in range(len(s)) :


         

        # Checking character in string


        if (s[i] == c):


            res = res + 1


    return res


     

     
# Driver code

str= "geeksforgeeks"


c = 'e'


print(count(str, c))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS