In Python, The function add_char_counts takes three parameters: a string s and two strings of length 1, char1 and char2, and returns the total number of times either char1 or char2 appears in s. For example, the word "scallions" has 2 s's and 1 n, so add_char_counts("scallions", "s", "n") returns 3. Hint: Use a string method to help solve this problem (count).
In Python, The function add_char_counts takes three parameters: a string s and two strings of length 1, char1 and char2, and returns the total number of times either char1 or char2 appears in s. For example, the word "scallions" has 2 s's and 1 n, so add_char_counts("scallions", "s", "n") returns 3. Hint: Use a string method to help solve this problem (count).
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
Related questions
Question
In Python, The function add_char_counts takes three parameters: a string s and two strings of length 1, char1 and char2, and returns the total number of times either char1 or char2 appears in s.
For example, the word "scallions" has 2 s's and 1 n, so add_char_counts("scallions", "s", "n") returns 3.
Hint: Use a string method to help solve this problem (count). You do not need an accumulator.
For example:
Test | Result |
---|---|
print(add_char_counts('Indiana', 'a', 'b')) | 2 |
print(add_char_counts('BAHAMAS', 'A', 'B')) | 4 |
print(add_char_counts('Mississippi', 'i', 'M')) | 5 |
print(add_char_counts("spam spam spam spam", "s", "p")) | 8 |
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT