Answer:
The solution code is written in Python:
- def convertCSV(number_list):
- str_list = []
- for num in number_list:
- str_list.append(str(num))
-
- return ",".join(str_list)
- result = convertCSV([22,33,44])
- print(result)
Step-by-step explanation:
Firstly, create a function "convertCSV" with one parameter "number_list". (Line 1)
Next, create an empty list and assign it to a new variable str_list. (Line 2)
Use for-loop to iterate through all the number in the number_list.(Line 4). Within the loop, each number is converted to a string using the Python built-in function str() and then use the list append method to add the string version of the number to str_list.
Use Python string join() method to join all the elements in the str_list as a single string. The "," is used as a separator between the elements (Line 7) . At the end return the string as an output.
We can test the function by calling the function and passing [22,33,34] as an argument and we shall see "22,33,44" is printed as an output. (Line 9 - 10)