Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created October 31, 2020 01:37
Show Gist options
  • Save ZechCodes/7b7368a036fab859677c281ab7828e10 to your computer and use it in GitHub Desktop.
Save ZechCodes/7b7368a036fab859677c281ab7828e10 to your computer and use it in GitHub Desktop.
Challenge 143 - Return First and Last Parameter

Challenge 143 - Return First and Last Parameter

Write two functions:

  • first_arg() should return the first parameter passed in.
  • last_arg() should return the last parameter passed in.

Examples

first_arg(1, 2, 3) ➞ 1

last_arg(1, 2, 3) ➞ 3

first_arg(8) ➞ 8

last_arg(8) ➞ 8

Notes

  • Return None if the function takes no parameters.
  • If the function only takes in one parameter, the first_arg and last_arg functions should return the same value.
from typing import Any, Optional
import unittest
def first_arg() -> Optional[Any]:
return # Put your code here!!!
def last_arg() -> Optional[Any]:
return # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(1, first_arg(1, 2, 3))
def test_2(self):
self.assertEqual('a', first_arg('a', 'b', 'c'))
def test_3(self):
self.assertEqual(8, first_arg(8))
def test_4(self):
self.assertEqual(None, first_arg())
def test_5(self):
self.assertEqual(3, last_arg(1, 2, 3))
def test_6(self):
self.assertEqual('c', last_arg('a', 'b', 'c'))
def test_7(self):
self.assertEqual(8, last_arg(8))
def test_8(self):
self.assertEqual(None, last_arg())
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment