I wrote code that is supposed to find the index of all the occurrences of a substring within a string, print them on the same line, and add a comma in between. I was not allowed to use lists, so I came up with the following:
string = input("Enter your string: ")
substring= input("Enter your substring: ")
print("Substring found at positions: ", end = "")
count = 0
while True:
count = string.find(substring, count+1)
if count == -1:
break
else:
print(str(count) + ",", end = " ")
However, I need to get rid of the last comma at the end, but I cannot figure out how without using a list. Any insight?