Reputation: 31
I'm writing a simple code to print the factor of a number from the user input. However, the next line of user input starts on the same line as the indexes of previous loop.
while True:
num = int(input('enter a number: '))
print('factor of {}: '.format(num), end = ' ')
for i in range (1,num+1) :
if num%i == 0 :
print(i, end = ' ')
Output:
enter a number: 32
factor of 32: 1 2 4 8 16 32 enter a number: 32
factor of 32: 1 2 4 8 16 32 enter a number: 32
factor of 32: 1 2 4 8 16 32
Upvotes: 0
Views: 41
Reputation: 346
You need to prepend \n
to the input line.
while True:
num = int(input('\nenter a number:'))
print('factor of {}: '.format(num), end = ' ')
for i in range (1,num+1) :
if num%i == 0 :
print(i, end = ' ')
Output
enter a number:32
factor of 32: 1 2 4 8 16 32
enter a number:32
factor of 32: 1 2 4 8 16 32
enter a number:
Upvotes: 1