0

In the example below I am trying to print the three variables I put in. If I try to separate the different inputs with commas, it gives me this error message:

ValueError: invalid literal for int() with base 10: '20,20,20'

If you need to know more, I'm happy to help.

A, B, C = int(input("how do I do this?"))
print(A)
print(B)
print(C)

2 Answers2

2

The following should do what you want:

A, B, C = (int(value) for value in input("how do I do this?").split(','))
print(A)
print(B)
print(C)
André C. Andersen
  • 8,955
  • 3
  • 53
  • 79
1

When you enter in the input "1,2,3", it's converted to [1, 2, 3] (using the split method) then each variable is assigned to an element of the list.

a, b, c = map(int, input("how do I do this?").split(","))
print(a)
print(b)
print(c)
sdzt9
  • 160
  • 7