Write a function to return True if the first and last number of a given list is same. If numbers are different then return False.
True
False
Given:
numbers_x = [10, 20, 30, 40, 10] numbers_y = [75, 65, 35, 75, 30]
Expected Output:
Given list: [10, 20, 30, 40, 10] result is True numbers_y = [75, 65, 35, 75, 30] result is False
Solution:
def first_last_same(numberList): print("Given list:", numberList) first_num = numberList[0] last_num = numberList[-1] if first_num == last_num: return True else: return False numbers_x = [10, 20, 30, 40, 10] print("result is", first_last_same(numbers_x)) numbers_y = [75, 65, 35, 75, 30] print("result is", first_last_same(numbers_y))
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer