Q1. Given an array of ints, return True if 6 appears as either the first or last element in the array. The array will be length 1 or more.
#first_last6([1, 2, 6]) → True
#first_last6([6, 1, 2, 3]) → True
#first_last6([13, 6, 1, 2, 3]) → False
#Code
my_list = []
in_list = list(map(int, input("Enter a multiple value: ").split()))
for num in in_list:
my_list.append(num)
if (my_list[0:] == 6 or my_list[:-1] == 6):
print("True")
else:
print("False")
code is working well but if the condition not working while else is working well like if we accessing the indexing "in_list[2]" in the else statement it will give the right answer. then why if condition is not working?
Aucun commentaire:
Enregistrer un commentaire