Respuesta :
Answer:
The solution code is written in Python 3.
- def convertDate(date_string):
- date_list = date_string.split("/")
- for i in range(0, len(date_list)):
- date_list[i] = int(date_list[i])
- return date_list
- print(convertDate('06/11/1930'))
Explanation:
Firstly, create a function convertDate() with one parameter, date_string. (Line 1).
Next, use the Python string split() method to split the date string into a list of date components (month, day & year) and assign it to variable date_list. (Line 3) In this case, we use "/" as the separator.
However, all the separated date components in the date_list are still a string. We can use for-loop to traverse through each of the element within the list and convert each of them to integer using Python int() function. (Line 5 - 6)
At last return the final date_list as the output (Line 8)
We can test our function as in Line 11. We shall see the output is as follow:
[6, 11, 1930]
The function that takes one parameter: a string (date_string) containing a date in the mm/dd/year format and return a list containing integers for each of the date components in month, day, year order is as follows:
def convert_date(date_string):
list1 = []
splits = date_string.split("/")
for i in splits:
list1.append(int(i))
return list1
print(convert_date('06/11/1930'))
Code explanation:
The code is written in python.
- We declared a function named "convert_date" and it has a parameter named "date_string".
- An empty list is declared.
- We used the split() function to remove "/".
- We used for loop to loop the variable "splits" and append the integer value of each value in the splits to the list1.
- We returned list1.
- Finally, we call the function with the required parameter.
learn more on function here: https://brainly.com/question/26104476
