Ask Question
19 January, 01:59

Write function modifyString (origString, charsToReplace, count) that takes as input a string origString, a string charsToReplace, and a positive integer count, and returns a new string such that each character in origString that occurs in charsToReplace is replaced by n consecutive copies of that character (with the same case as in the original). For example,

+1
Answers (1)
  1. 19 January, 03:37
    0
    The code of the above program is provided below. using Python

    Explanation:

    Code in Python 3:-

    def modifyString (origString, charsToReplace, count):

    # Make s1 as original string

    s1=origString

    # Make s2 as charsToReplace string in lowercase

    s2=charsToReplace. lower ()

    # Make s3 as charsToReplace string in uppercase

    s3=s2. upper ()

    # Initialize answer as an empty string

    ans=''

    # Iterate the string upto length times

    for i in range (len (s1)):

    # check for chars in the string and append to the answer

    if (s1[i] in s2) or (s1[i] in s3):

    ans=ans+count*s1[i]

    else:

    ans=ans+s1[i]

    # return the final string

    return ans

    print (modifyString ("Our cat is funny","aeiou",5))

    print (modifyString ("Our cat is funny","zu",3))
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write function modifyString (origString, charsToReplace, count) that takes as input a string origString, a string charsToReplace, and a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers