2 תשובות
לא עשיתי את הקורס אבל עובד די הרבה אם פייטון תשמש באיזשהו ai קלוד או chat gpt
def format_list(my_list):
""" gets a list of even length. returns a string which contains the
elements in even indexes, seperated with a comma and a space except the
last one which is seperated whit an and and a space. see main for ex.
:param my_list: the list which the function will work on
:type my_list: list
:return: the wanted string as mentioned above
:rtype: str
"""
even_list = my_list[::2]
formatted_str = ', '.join(even_list) + ' and ' + my_list[-1]
# join joins all items in the list and separates them with the given string
return formatted_str

def main():
my_list = ["hydrogen", "helium", "lithium", "beryllium", "boron", "magnesium"]
print(format_list(my_list))

if __name__ == "__main__":
main()