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:


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -