Question

In: Computer Science

find how many times a letter appear in a string for example yellowstone letter l appear...

find how many times a letter appear in a string for example yellowstone letter l appear two times
(using python)

Solutions

Expert Solution


#Python program count.py
#main method
def main():

    #set name
    name ="yellowstone"
    #set letter
    letter='l'

    #print Name
    print('Name :%s'%name)
    #print letter
    print('Letter: %c'%letter)
    #calling count
    c=count(name, letter)
    #print c
    print('count: %d'%c)

#Method count that takes name and letter
#as input arguments and returns number of times
#letter occurs in name
def count(name, letter):
    counter=0
    for i in name:
        if letter==i:
            counter+=1
    return counter
#calling main method
main()

------------------------------------------------------------------------

Sample output:

>>>
Name :yellowstone
Letter: l
count: 2


Related Solutions

Assuming that each letter can appear at most once in an arrangement, how many ways are...
Assuming that each letter can appear at most once in an arrangement, how many ways are there to arrange 10 letters taken from the alphabet a-z such that: a) Both a and z are included in the arrangement? b) Exactly one of a and z appears in the arrangement? The intention here is that exactly one element from the set {a,z} appears in the string. So, abcdefghij and bcdezfghij are OK, but abcdezfghi is not. c) z and a appear...
How many times will an "X" appear in the following nested loop? for (outer = 0;...
How many times will an "X" appear in the following nested loop? for (outer = 0; outer <=5; outer++) {for (inner = 1; inner <=4; inner+1) {cout<<("X");} } 9 10 20 24 none of the above
Java Write a method that counts how many times one string appears in another string. The...
Java Write a method that counts how many times one string appears in another string. The method takes three input parameters: two Strings and one Boolean. The Boolean value determines whether the words are allowed to overlap each other. For example: When the method is called with input parameters (“balloon”, “oo”, false), it returns 1. When the method is called with input parameters (“hh”, “hhhhhh”, true) returns 5. When the method is called with input parameters (“cc”, “abcdefg”, true), returns...
String search   Describe the brute force solution to counting the number of times the letter “a”...
String search   Describe the brute force solution to counting the number of times the letter “a” occurs in a text. Outline a divide-and-conquer algorithm for counting the number of times the letter “a” occurs in a text. Analyze each approach and compare the efficiencies.
use java recursion find # of times a substring is in a string but it has...
use java recursion find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters. input is 2 strings, output is an int input: ("Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "hello") should output: 3 input: (" Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "Hello") should output: 1 input: (" Hello...
use java recursion find # of times a substring is in a string but it has...
use java recursion find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters. input: school is boring with schooling and School substring: school output: 1
How many arrangements of INCONSISTENT are there in which NE appear consecutively or NO appear consecutively...
How many arrangements of INCONSISTENT are there in which NE appear consecutively or NO appear consecutively but not both NE and NO are consecutive? The answer is 2x11!/2!2!2!2! - 2x10!/2!2!2! Please show me how to get the answer, it's important for my midterm, thanks.
1. Use the Fundamental Principle of Counting to find how many possible 5-letter phrases can be...
1. Use the Fundamental Principle of Counting to find how many possible 5-letter phrases can be made where each phrase has the following qualities: It starts with two numbers and ends with three letters, and the two numbers can’t be the same number. Good examples: 87RFE 20JWJ Bad examples: 33UPD 11LPX 2. From a standard 52-card deck, how many ways can you be dealt a 4-card hand that is a 3-of-a-kind of K’s? (exactly three K’s and one other card)...
There are many times that debt can be advantageous for a company. Provide an example of...
There are many times that debt can be advantageous for a company. Provide an example of a company that took on too much debt and what eventually happened. Attach an article and introduce us to why they took on the debt and what happened.
How many times should the following C code print "Example" and draw a process graph #include...
How many times should the following C code print "Example" and draw a process graph #include <stdio.h> #include <sys/types.h> #include <unistd.h> void try() { fork(); printf("Example\n"); fork(); return; } int main() { try(); fork(); printf("Example\n"); exit(0); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT