0
for i in range(n - 1):
        nums = int(input('Enter numbers: '))

INPUT:

Enter numbers: 1
Enter numbers: 2
Enter numbers: 3
Enter numbers: 4

This is the output I am getting but I want the output to be in a single line, numbers that I am entering should be in a single line like 1 2 3 4. No commas no apostrophe

Please tell any solution

3
  • Sorry, I want to ask if you want the output to have no commas and no apostrophe after inputting the above 4 numbers? Commented Mar 11, 2022 at 1:57
  • I want to take multiple inputs like eg 5 in a single attempt and add those inputs Commented Mar 11, 2022 at 19:12
  • You can use join to get your output Commented Mar 11, 2022 at 23:52

2 Answers 2

1

You can ask for a single input and then split it into words with the str.split() method

# Get the input
nums = input('Enter numbers :')

# Split and map to `int`
nums = nums.split()
nums = list(map(int, nums))

Sign up to request clarification or add additional context in comments.

Comments

0

You can append it first into a list

def myfunction(n):
    return [input('Enter numbers: ' for _ in range(n - 1)]

numbers = myfunction(5)

Enter numbers: 1
Enter numbers: 2
Enter numbers: 3
Enter numbers: 4

And then, you can use " ".join(numbers)

result = " ".join(numbers)
print(result)

1 2 3 4

If you do not even want to have the space:

result2 = "".join(numbers)
print(result2)

1234

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.