CodeSolved

A comprehensive source of programming questions and exercises

The number of replications of the character in the string

Practice Easy 67/ Download 2900 Views

Write a function that returns the number of repetition of a character in a string

You should not use ready -made functions for this question


count_char("hooshang", "o") #2

11 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
```def duplicate_string(string,char):
    """
    این تابع برای نشان دادن تعداد حروف تکراری 
    در یک استرینگ است 
    """
    # Wear the variable value zero and the desired string with the circle
    count = 0
    for i in string :
        if i == char:   # If the characters in the navigation were one with our second entrance
            count += 1  # Add one number to Kant
    return count        # Print out the output
# Frequently function and give two inputs to the function
filter_char = duplicate_string("mohammad","m")
print(filter_char)```
function count_1(s, c) {
  let count = 0;
  for (let char in s) {
    if (char === c) {
      count += 1;
    }
  }
  return count;
}

const result = count_1("h", "o");
console.log(result);
def count_char(txt,char):
    count=0
    for i in t:
        if c==i:
            count+=1
    print(count if count>0 else 'nout found')

t=input('enter your text: ')
c=input('enter your char: ')   
count_char(t,c)
User 35 Download Python
def string_txt(s): 
    my_text = {}
    for item in s:
        if item in my_text:
            my_text[item] += 1
        else:
            my_text[item] = 1
    return my_text
User 918 Download Python
def chek_try_str(string,char):
    return string.count(char)
text=input('input one string:')
char=input('input char for count:')
print(f"the character appears'{char}',{chek_try_str(text,char)} times in the string.")
Maryam.n Download Python
def count(x,y):

    l=[]
    for i in x:
        l.append(i)
    l2=filter(lambda x : True if x==y else False , l)
    return len(list(l2))


print(count('hooshang',"o")) #2
User 716 Download Python
# Number
def count_char(string, char):
    return string.count(char)
print(count_char("hooshang", "o"))
Nasrin.zia Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close