python 3.x - code printing wrong answer -
write function first_last6(nums) takes list of ints nums , returns true if 6 appears either first or last element in list. list of length 1 or more.
my code:
def first_last6(nums): if nums[0] or nums[-1] == "6": return true else: return false
it not returning right answer test:
print(first_last6([3, 2, 1]))
its suppose false
, while prints true
.
the original test checks if nums[0] true or if nums[-1] 6, check if either 6, should use:
if nums[0] == 6 or nums[-1] == 6: