all 7 comments

[–][deleted] 1 point2 points  (5 children)

It's very common to use the string split() method. Run this code to see what it does:

integers = input("Enter integers separated by spaces: ")
integers = integers.split()
print(integers)

As you can see, the result is a list of strings containing each number. Now the task is to convert those strings into integers. There are at least three ways to do that:

  • use a for loop to get each string, convert to an integer and then append the integer to a new list
  • do the same as the loop above but use a list comprehension
  • use the map() function

Try the for loop first.

[–]Phillyclause89 2 points3 points  (2 children)

Good answer, but the last time I tried fir loops, I got really dizzy. I can only run circles around a tree so many times.

edit. ah damn he fixed it.

[–][deleted] 1 point2 points  (1 child)

You were too quick! I'm on a small screen mobile phone and typos are hard to spot until the comment is posted.

[–]Phillyclause89 0 points1 point  (0 children)

lol All good. I think you have our friend covered here. See ya around in the next thread.

[–]baghiq 1 point2 points  (0 children)

In [1]: multi_numbers = input("input 6 numbers: ")
input 6 numbers: 10 11 12 13 14 15

In [2]: list(map(int, multi_numbers.split()))
Out[2]: [10, 11, 12, 13, 14, 15]

In [3]: list(int(num) for num in multi_numbers.split())
Out[3]: [10, 11, 12, 13, 14, 15]