0

I have the following code:

print('Phase 1: Gather user input')
print('--------------------------')

# function to verify the user entered an integer greater than 0
def verifyPositve(x):
    try:
        return int(x) >= 0
    except ValueError:
        return False

print('Please enter integer values, as error-checking has not yet been implemented.')

while True:
    x = input('Enter a positive number: ')
    if verifyPositve(x) == True:
        numList.append(x)
    elif x == 'done':
        break
    else:
        print('You did not pick a positive number.')

print('Numbers entered: %s' % (numList))

On the final print statement, I am attempting to include the numbers from the list without the braces or commas.

I found this solution on Stackoverflow but I can't figure out how to implement it in the same line as "Numbers entered:".

I just keep finding the same solution in searches. Any suggestions or links to a reference on how to solve this?

Thank you for your time.

EDIT: This has been solved in the comments with the following code:

print('Numbers entered: %s' % ', '.join(numList)))

Not sure how to close it or if I just leave it open.

Thank you all.

DougM
  • 920
  • 1
  • 9
  • 21

2 Answers2

0

Just use join() like in the examples, but convert all the numbers to str.

numList = [1, 2, 3]

print('Numbers entered: %s' % ' '.join(map(str, numList)))
#Numbers entered: 1 2 3
Jab
  • 26,853
  • 21
  • 75
  • 114
0

I ended up using the solution recommended by Primusa

print('Numbers entered: %s' % ', '.join(numList))
DougM
  • 920
  • 1
  • 9
  • 21