Test Cases are satisfied while running the code but fails on submission in codekata

Problem Statement:
Given a number N, print its factors.

Input Description:
Input Size : n<=1000

Sample Input:
6

Sample Output:
1 2 3 6

My Solution

n = int(input())

i = 1
while i < n + 1:
    if n % i == 0:
        print(i, end=" ")
        
    i += 1

I tried using if statement as well

n = int(input())

for i in range(1, n + 1):
    if n % i == 0:
        print(i, end=" ")

For both the codes, the 2/2 test cases are satisfied on running the code. But after submission, the test cases fails, resulting in 0/5 test cases satisfied.

Need help!!

Dear user,

In codekata platform end of the output space not allowed, so you can code it without space at the end of the line