-1

We can get 3 number from user like this

a = int(input())
b = int(input())
c = int(input())

Now how can we get 3 number from user in one line?

a , b , c = int(input())

I tried this but it's not ok

ariankazemi
  • 105
  • 3
  • 14
  • 2
    `a, b, c = int(input()), int(input()), int(input())` – but there's really no point in doing that. You should avoid trying to fit things into a single line “just because”. – poke Sep 05 '21 at 12:24
  • get the input string, `.split()` it by whatever separator is between the numbers (space, comma?), and convert each of the split parts into a number separately. – yedpodtrzitko Sep 05 '21 at 12:24

4 Answers4

1

try this:

a , b , c = map(int,(input().split()))
I'mahdi
  • 23,382
  • 5
  • 22
  • 30
0

You can do like this:

a, b, c = input("Insert the 3 values: ").split()
print(f"a: {a}\nb: {b}\nc: {c}")

See this similar question for more details

Unused hero
  • 307
  • 1
  • 9
0

If you're reading data from a .txt file and you're wanting to map variables a, b, and c in one line.

Example:

inputFile = open("example.txt",r)

a, b = map(int, inputFile.readline().split())
bad_coder
  • 11,289
  • 20
  • 44
  • 72
VintageMind
  • 65
  • 2
  • 9
-1
try:
    a,b,c  = map(int,input('input').split())

    print(a,b,c)
    
except:
    print('input is no good')
pippo1980
  • 2,181
  • 3
  • 14
  • 30