-4

actually, I have a problem with this sort of input. can you tell me how can I do it in the correct way?TNX this is my code:

x,y,z=int(input()).split(" ")

but it shows this error:

invalid literal for int() with base 10:

Sreeram TP
  • 11,346
  • 7
  • 54
  • 108
pouria.m
  • 3
  • 3
  • What is the input to this program? Please review the [mcve] and [ask] pages how to help us help you. – MisterMiyagi Apr 21 '21 at 09:36
  • Note that ``int(input()).split(" ")`` *first* attempts to parse the entire input to *a single* ``int``, *then* attempts to split the integer on whitespace – neither of which makes sense. You should likely use ``map(int, input().split(" "))`` or ``map(int, input().split())``. – MisterMiyagi Apr 21 '21 at 09:37
  • Does this answer your question? [Get a list of numbers as input from the user](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user) – MisterMiyagi Apr 21 '21 at 09:40

3 Answers3

0
x, y, z = map(int, input().split(" "))
lolloz98
  • 111
  • 5
0

I think you are trying to read 3 space separated integers from stdin.

You are trying to split an int in the code, which will not work out.

You have to split the input and then convert the individual items to int.

See the code below,

inputs = input().split(" ")
x = int(inputs[0])
y = int(inputs[1])
z = int(inputs[2])

You can use map and do this in one line,

x,y,z = map(int, input().split(" "))
Sreeram TP
  • 11,346
  • 7
  • 54
  • 108
0

This is the closest working example to what you are trying to achieve (you need to do the integer conversion of each individual item in the list):

x,y,z = (int(num) for num in input().split(" "))

However the use of map as suggested by other reviewers would be the preferred way to go. Also, depending on where you are utilizing this, you may wish to sanitize/validate your inputs - what do you expect to happen if the input contains 2 numbers? 4 numbers? Values which aren't numbers?

Neil Studd
  • 174
  • 8