In: Computer Science
In Python write a loop that tests whether two lists contain the same integers in the same order:
listA = [1, 2, 3, 4]
listB = [1, 2, 3, 4]
equal = True
for ______ in ______:
if _______ != ________ :
_______ = ________
if equal:
print(_______)
else:
print(_______)
Program:
# define first list
listA = [1, 4, 3, 2]
# define second list
listB = [1, 2, 3, 4]
# initially set equal as true
equal = True
# Take each element from first and second list
for (data1, data2) in zip(listA, listB):
# check both value are equal
if data1 != data2:
# Change equal as False
equal = False
# check equal is true
if equal:
# then print both lists contain the same integers in the same order
print("lists contain the same integers in the same order")
# if not
else:
# then print both lists contain not same integers or not in the same order
print("lists contain the not the same integers and not in the same order")
Screenshot:
.