Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8737643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:34:22+00:00 2026-06-13T10:34:22+00:00

Assignment: Return the number of occurrences of character c in string s , ignoring

  • 0

Assignment:

Return the number of occurrences of character c in string s,
ignoring case. Use loops. Do not use the in-built string method count,
which does a similar thing. The idea is to learn to write loops. You
should ignore case when comparing a character of s with c.

My attempt:

 def countletter(s, c): #BAD
     count = 0
     for c in s:
        if c == c:
        count += 1
        return count

Am I on the right track? I seem to get some assertion errors when I test it in the main…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:34:23+00:00Added an answer on June 13, 2026 at 10:34 am

    your return is at wrong place. So your function is actually returning only after one iteration.

    Also you should not use the variable name c in for loop, use some different variable, as it replaces the value of c recieved from the function call with the current character being fetched by the for-loop.

    def countletter(s, c): #BAD
        count = 0
        for x in s:
            if x.lower() == c.lower():
                count += 1
        return count
    
    
    print countletter("abcdefFf","F") #prints 3
    print countletter("a","A")        #prints 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do an assignment in which I am to use multiple
I'm asked to create a method that returns the number of occurrences of a
I have two tasks for an assignment, one return the number of bits in
For an assignment, we were asked to create a function which returns an inverse
Assignment of NSFileOwnerAccountName and NSFileGroupOwnerAccountName does not work? The directory created defaults to my
My assignment is to write an overloaded version of iquote() , a method that
I have this method: public static int what(String str, char start, char end) {
I have an assignment for uni in which I have to implement a binary
I've completed a OOP course assignment where I design and code a Complex Number
Disclaimer: This is for an assignment. I am not asking for explicit code answers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.