-5

could you please help me with the following?:

I need a code that returns True if the first and last numbers in a list are the same or False if the numbers are different.

def first_last_same(numberList):
    print("On the list:", numberList)

#Here the code#

I need when i print

print("The first and last numbers in the list are the same", first_last_same([10, 20, 30, 40, 10]))
print("The first and last numbers in the list are the same", first_last_same([57, 22, 35, 57, 22, 57]))

Generate the following result

On the list: [10, 20, 30, 40, 10]
The first and last numbers in the list are the same True
On the list: [57, 22, 35, 57, 22, 58]
The first and last numbers in the list are the same False

Please, help.

  • 1
    Please add your approach or issue you are facing this help to understand the problem you're facing with your solution – Ashish Oct 30 '21 at 10:13
  • To learn a new language, it's better to try and research a new concept. syntax ... rather to ask people for `answer` directly. – Daniel Hao Oct 30 '21 at 10:45
  • This [answer](https://stackoverflow.com/a/69778674/7758804) was actually posted 17 seconds before the accepted answer, and `return` in the accepted answer is not needed, since nothing is returned. – Trenton McKinney Oct 30 '21 at 13:24

3 Answers3

1
if (a[0]==a[-1]):
    print(True)
else:
    print(False)
1
def first_last_same(numberList):
    if numberList[0] == numberList[-1]:
        print("first and end is same")
    else:
        print("not the same")
0
def first_last_same(numberList):
    if numberList[0] == numberList[-1]:
        print("On the list:", numberList)
        print("The first and last numbers in the list are the same", True)
    else:
        print("On the list:", numberList)
        print("The first and last numbers in the list are the same", False)
    return
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Ruggero
  • 427
  • 2
  • 10