Using python and while loop only, Write code that takes a string and a list of c
ID: 3722382 • Letter: U
Question
Using python and while loop only,
Write code that takes a string and a list of characters from the user, and returns the number of occurrences of any of the characters in the string. Below are some examples:
‘hello’ and [‘l’] will return 2
‘hello’ and [‘l’,’o’] will return 3
‘hello’ and [‘q’] will return 0
You may not use any built-in functions/methods besides len().
Template:
def countChars(string, list):
string = string
chars = list
#YOUR CODE GOES HERE (indented)
return 0
#END YOUR CODE
Write code that takes a string and a list of characters from the user, and returns the number of occurrences of any of the characters in the string. Below are some examples:
‘hello’ and [‘l’] will return 2
‘hello’ and [‘l’,’o’] will return 3
‘hello’ and [‘q’] will return 0
You may not use any built-in functions/methods besides len().
Template:
def countChars(string, list):
string = string
chars = list
#YOUR CODE GOES HERE (indented)
return 0
#END YOUR CODE
Explanation / Answer
def countChars(string, list): string = string chars = list count = 0 i = 0 while iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.