Answer to Question #330854 in Python for Sind

Question #330854

You are given two strings of same length and comprosied of + and - , print a new string that shows the result of the interaction of the two strings assume the following rules.



Interaction between two positive characters results in a positive character.



( "+" Against a "+" returns another "+")



Interaction between two negative characters results in a negative character.



("-" Against a "-" returns another "-")



Interaction between a positive and a negative character results in a " 0" (Neutral)



("+" against a "-" returns a "0")




Input: ++++++ ------



Output: 000000



Input: +-----+++- --+-+-++--



Output: 0-0-0-++0-





1
Expert's answer
2022-04-19T08:07:09-0400
def str_dif(s1, s2):
    if len(s1) != len(s2):
        return
    res = ''
    for i in range(len(s1)):
        if s1[i] == s2[i]:
            res += s1[i]
        else:
            res += '0'
    return res


def main():
    line = input()
    s1, s2 = line.split()
    res = str_dif(s1, s2)
    print(res)


main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS