Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change the function codeCalc(s,n) to take s, a string of characters delimited by

ID: 3783651 • Letter: C

Question

Change the function codeCalc(s,n) to take s, a string of characters delimited by “;” and n a list of characters. The program will take each character in the string, find the index where it is in n (if it is there) and return the sum of the indices where each character in s was found in n. If the character is not in s then nothing will be added and the program will continue to the next character in s. s can be an empty string but n will always have something in it

Code Change 'a :b;a;d', a 'b', 'C', 'd' 1) code Change a :b: a d;b;b:b', a b 'C', 'd' 1) code Change a 'b', c', d' 1)

Explanation / Answer

def codeCalc(s,n):
   s = s.split(';')
   ans = 0
   for ch in s:
       for i in range(0,len(n)):
           if(ch==n[i]):
               ans += i
   return ans
an = codeCalc('a;b;a;d',['a','b','c','d'])
print(an)
an = codeCalc('a;b;a;d;b;b;b',['a','b','c','d'])
print(an)
an = codeCalc('',['a','b','c','d'])
print(an)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote