Ask Question
21 September, 10:12

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,

+3
Answers (1)
  1. 21 September, 10:29
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers