1

The input is integers separated by a space in the form below: 180 141 142 175 162

busnumbers = input().split()

for n in busnumbers:
    n = int(n)

I want busnumbers = [ 180,141,142,175,162] Instead, I have ['180','141','142','175','162'] Why isn't the conversion working?

Naya Keto
  • 123
  • 3
  • 8
  • Even if you put integers for your input, they will always be read as a string. You have to explicitly convert them to an `int`. Look at the link provided. – idjaw Jul 23 '18 at 02:17

1 Answers1

1

Because n variable that you apply int() is not transform data in list. It just transforms each data in the loop.

If you want to use above code it would be

for i,v in enumerate(busnumbers): busnumbers[i] = int(v)

busnumbers = list(map(int, input().split()))

lifez
  • 318
  • 1
  • 4
  • 9