-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

  • 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
  • 11,310
  • 3
  • 17
  • 23
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

kisa lisa
  • 187
  • 7
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
  • 8,684
  • 19
  • 37
  • 59
VintageMind
  • 55
  • 2
  • 9
-1
try:
    a,b,c  = map(int,input('input').split())

    print(a,b,c)
    
except:
    print('input is no good')
pippo1980
  • 1,419
  • 3
  • 9
  • 22