Question

write a function call character_thing (string, character) that takes in a string and a character. The...

write a function call character_thing (string, character) that takes in a string and a character. The function will return the number of times the character appears in the string.

please be in python

Homework Answers

Answer #1

Python code:

#defining character_thing function
def character_thing(string,character):
#initializing count as 0
count=0
#looping each character in string
for i in string:
#checking if it is the required character
if(i==character):
#incrementing count
count+=1
#returnining count
return count
#calling character_thing function for a sample string and character and printing the result
print(character_thing("hii","i"))

Screenshot:


Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
Please code in Java Write a recursive method that takes a string and return a string...
Please code in Java Write a recursive method that takes a string and return a string where every character appears twice. For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it.
C++: Write a function that receives a pointer to a character string consisting of only alphabets...
C++: Write a function that receives a pointer to a character string consisting of only alphabets a-z and returns the character with the maximum number of repetitions. If more than one-character repeats same number of times, return the character with smallest alphabetical order. For example, the string “Mississippi” has three repeated characters (i-4, s-4, p-2). Both ‘i’ and ‘s’ repeated 4 times but ‘i’ is alphabetically smaller hence the function should return ‘i’. Do not count repeated blanks, special characters,...
Write a function that takes as input an English sentence (a string) and prints the total...
Write a function that takes as input an English sentence (a string) and prints the total number of vowels and the total number of consonants in the sentence. The function returns nothing. Note that the sentence could have special characters such as dots, dashes, and so on. write a python program please.
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
Python Write function stringCount() that takes two string inputs—a file name and a target string— and...
Python Write function stringCount() that takes two string inputs—a file name and a target string— and returns the number of occurrences of the target string in the file. >>> stringCount('example.txt', 'line') 4
using python Write function stringCount() that takes two string inputs—a file name and a target string—...
using python Write function stringCount() that takes two string inputs—a file name and a target string— and returns the number of occurrences of the target string in the file. >>> stringCount('example.txt', 'line') 4
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and...
Write a cencrypt() function that takes a arbitrary length string and an integer as inputs and returns a string as output. The cencrypt() function you write in lab today needs to work on strings that contain upper-case letters, lower-case letters, or both. The output string should be all upper-case letters. (The Romans of Caesar's time used only what today we call upper-case letters.) So a call to cencrypt("Caesar", 1) should return (return not print) the string “DBFTBS” and a call...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Write a Python function that computes the frequency of characters in a string s. The function...
Write a Python function that computes the frequency of characters in a string s. The function should return a map where the key is the character and the value is the count. Make sure you include a main function and include comments to document your code.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT