Try join()
to convert your list to string -
" ".join(map(str, li))
Here your list is a list of integers and join()
joins every string element of an iterable separated by some string (in this case " "). So, you need to convert each integer to a string first. map()
can do that. map()
takes a function and apply it on each element of an iterable which is passes as the second arguement (here list li
). So, map(str, li)
will create an iterable where each element is a string representation of every element of list li
So, your line would be-
print("Case {}: {}".format(case_no, " ".join(map(str, li)), sep=' ', end=''))
You can use generator expression for that too -
print("Case {}: {}".format(case_no, " ".join(str(i) for i in li), sep=' ', end=''))
In this case you are using a generator expression (think of it like list comprehension if you don't know). The generator expresssion iterates over every element of li
and returns a stringified (don't know if that's the word) version of that element.
Also, if you just want to print the list and not maintain it for other purposes then you can just simplify it a bit -
t = int(input())
for case_no in range(1, t+1):
n = int(input())
print("Case {}: {}".format(case_no, " ".join(str(i) for i in range(1, n+1) if not n % i), sep=' ', end=''))