migrate to git.charlotte.sh

This commit is contained in:
Charlotte Croce 2025-04-19 23:42:08 -04:00
commit fbd588721e
412 changed files with 13750 additions and 0 deletions

View file

@ -0,0 +1,10 @@
def first_element(list_to_search):
"""Returns the first element of the supplied list. Returns None if the list was empty"""
if len(list_to_search) == 0:
return None
return list_to_search[0]
# Leave this part for easily testing your function
print('[4, 2, 15, 5] The first_element returns', first_element([4, 2, 15, 5]))
print('[] The first_element returns', first_element([]))

View file

@ -0,0 +1,10 @@
def second_element(list_to_search):
"""Returns the second element of the supplied list. Returns None if list contains less than 2 elements"""
if len(list_to_search) < 2:
return None
return list_to_search[1]
# Leave this part for easily testing your function
print('[4, 2, 15, 5] The second_element returns', second_element([4, 2, 15, 5]))
print('[3] The second_element returns', second_element([3]))

View file

@ -0,0 +1,11 @@
def last_element(list_to_search):
"""Returns the last element of the supplied list.
Returns None if the list is empty"""
if len(list_to_search) == 0:
return None
return list_to_search[-1]
# Leave this part for easily testing your function
print('[4, 2, 15, 5] The last_element returns', last_element([4, 2, 15, 5]))
print('[] The last_element returns', last_element([]))

View file

@ -0,0 +1,13 @@
def area_code(phone_number):
""" Given a phone number in the format: 802-555-1212
extract the first 3 characters and return this as a string
:param phone_number: (str) Must be formatted "XXX-XXX-XXXX"
:return: (str) 3 digit area_code
"""
return phone_number[:3]
# Leave this part for easily testing your function
print('"802-555-1212" area_code returns', area_code("802-555-1212"))
print('"410-617-3452" area_code returns', area_code("410-617-3452"))

View file

@ -0,0 +1,12 @@
def last_four_digits(phone_number):
""" Returns the last 4 digits of a phone number as a string
:param phone_number: (str) May be formatted "XXX-XXX-XXXX" or "1-XXX-XXX-XXXX"
:return: (str) last four digits
"""
return phone_number[-4:]
# Leave this part for easily testing your function
print('"802-555-1212" last_four_digits returns', last_four_digits("802-555-1212"))
print('"1-410-617-3452" last_four_digits returns', last_four_digits("410-617-3452"))

View file

@ -0,0 +1,13 @@
def first_last_name(full_name):
""" Returns a tuple with the first and last name.
:param full_name: (str) Contains a first and last name seperated by a space.
There is only a single space in the full_name.
:return: (tuple) Tuple containing first and last names
"""
return tuple(full_name.split(" "))
# Leave this part for easily testing your function
print('"Billie Holiday" first_last_name returns', first_last_name("Billie Holiday"))
print('"James Brown" first_last_name returns', first_last_name("James Brown"))

View file

@ -0,0 +1,15 @@
def second_smallest(numbers):
"""Returns the second smallest number
:param numbers: (list) List of numbers of at least size 2
:return: (int or float) The second smallest number
"""
numbers.sort()
return numbers[1]
# Leave this part for easily testing your function
print('[6, 3, 9, 2, 1] second_smallest returns', second_smallest([6, 3, 9, 2, 1]))
print('[23, 23.25, 23.5, 23] second_smallest returns', second_smallest([23, 23.25, 23.5, 23]))

View file

@ -0,0 +1,24 @@
def area_code(phone_number):
"""Returns the area code of the supplied phone number.
params:
phone_number (string) in the format:
1-XXX-XXX-XXXX
XXX-XXX-XXXX
(XXX)-XXX-XXXX
return: (string) The area code
"""
if phone_number[0] == '(':
return phone_number[1:4]
elif phone_number[0] == '1':
return phone_number[2:5]
else:
return phone_number[:3]
# Leave this part for easily testing your function
print('"1-617-555-1212" area_code returns', area_code("1-617-555-1212"))
print('"802-999-1212" area_code returns', area_code("802-999-1212"))
print('"(802)-999-1212" area_code returns', area_code("(802)-999-1212"))