Currently learning python modules and functions and the task is to simply display a list without any built in functions (other than range()
and str()
, can't use slice expressions, list methods or string methods either.
So using this that we're not supposed to edit:
list1 = ['q', 'w', 'e', 'r', 't', 'y']
emptyList = []
string = my_string(list1)
print(string)
print(my_string(emptyList))
and this that I made myself:
def my_string(first_list)
my_string = "List: "
for x in range(len(first_list)):
my_string += str(first_list[x]) + ", "
return my_string[:-2]
currently outputs:
List: q, w, e, r, t, y
List
The correct output should be:
List: q, w, e, r, t, y
List:
The slice that i'm not supposed to use cuts off the final comma on the first list, however also takes of the colon on the second. How would I go about removing the final comma and keeping the colon without using a slice expression?
I'd normally ask my prac tutor but I don't have another lesson for another week