Q. Write a program that input two tuple seq_a and seq_b and print True if every element in seq_a is also an element of seq_b , else print False.


You can understand by Watching video :-



Answer :-

tup1 = eval(input("Enter first tuple = "))
tup2 = eval(input("Enter second tuple = "))
count = 0
if len(tup1)==len(tup2):
    for i in range(len(tup1)) :
        if tup1[i] == tup2 [ i ] :
            continue
        else :
            count += 1
    if count == 0  :
        print("True")
    else :
        print("False")
else :
    print("False")

Output :-

Enter first tuple = (1,2,3,4,5,6,7,8,9)
Enter second tuple = (1,2,3,4,5,6,7,8,9)
True

>>> 

Enter first tuple = (1,2,3,4,5,6,7,8,9)
Enter second tuple = (1,2,3,4,5,6,7,8)
False

>>> 

Enter first tuple = (1,3,5,7)
Enter second tuple = (2,4,6,8)
False

>>> 


6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. you could have just used
    if tup1[i] != tup2 [ i ]:
    print('False')
    else:
    continue
    print('True')#Outside the loop

    ReplyDelete
  2. I need outputs for all question

    ReplyDelete
  3. Why can't we use "in" operator to check

    ReplyDelete
    Replies
    1. because "in" keyword will check all element at one time.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post