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
>>>
you could have just used
ReplyDeleteif tup1[i] != tup2 [ i ]:
print('False')
else:
continue
print('True')#Outside the loop
try it...
DeleteI need outputs for all question
ReplyDeleteOk, we will try to provide all outputs.
DeleteWhy can't we use "in" operator to check
ReplyDeletebecause "in" keyword will check all element at one time.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )