Answer to Question #298523 in Python for Michael

Question #298523

Bhanu and Soham are good friends. Yesterday they have given an exam in which there were given two different set of questions to solve. Bhanu was given set A and Soham was given set B. After examination they want to cross check their answers. For this they need to identify common questions in their sets. Write a python function Check_Common(A, B) which takes two sets A and B as a input and return true if any common question found otherwise return false.


 

Example-1

Example-2

Input:

{1, 2, 3, 4}

{4, 5, 6, 7}

 

Output:

True

Input:

{1, 2, 3, 4}

{5, 6, 7, 8}

 

Output:

False

 




1
Expert's answer
2022-02-16T10:21:19-0500
def Check_Common(A, B):
    for a in A:
        if a in B:
            return True
    return False


def main():
    print('Example-1')
    A = {1, 2, 3, 4}
    B = {4, 5, 6, 7}
    print('A =', A)
    print('B =', B)
    print(Check_Common(A, B))
    print()

    print('Example-2')
    A = {1, 2, 3, 4}
    B = {5, 6, 7, 8}
    print('A =', A)
    print('B =', B)
    print(Check_Common(A, B))

if __name__ == '__main__':
    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