Pasting multiiple lines (read as single line/inputs) into Spyder console

Viewed 205

So, say I have to take 3 inputs from the user (name, age, location):

Jim Halpert
30
Scranton

and I write the code as follows:

name = input()
age = input()
location = input()

Now, instead of typing them one by one, I just copy and paste them from a text file, but when I paste them into the console they are not read as separate inputs. In fact, they are shown as follows:

Jim Halpert
...: 30
...: Scranton

My question is: Is there any way I can make Spyder read them as separate inputs? Thank you for your help.

1 Answers

you could use .splitlines()


name, age, location  = input().splitlines()
print(name)
print(age)
print(location)

all three variables would also be stored as strings in this case. If you do math on age you would need to convert it.

age = int(age)

if all the inputs were ints for example you could do

x, y, z = [int(x) for x in input().splitlines()]   
Related