JC Senkpiel
JC Senkpiel

Reputation: 9

I'm trying to write a line of code at ask the user for two inputs but can't figure out how to complete this

Why does this line of code not split the two

Lat1,long1 = input("Enter the Lat and Long of the source point separated by a comma eg 20,30").split()

Upvotes: 0

Views: 31

Answers (1)

idjaw
idjaw

Reputation: 26578

By default using split() will only split on a space. You are asking the user to enter two entries separated by a ,, so you will end up getting a

ValueError: not enough values to unpack (expected 2, got 1)

To resolve this, you need to split on the identifier you are looking to split with. In this case it is a ',', so call split as split(','):

Lat1,long1 = input("Enter the Lat and Long of the source point separated by a comma eg 20,30").split(',')

Demo:

>>> Lat1,long1 = input("Enter the Lat and Long of the source point separated by a comma eg 20,30").split(',')
Enter the Lat and Long of the source point separated by a comma eg 20,3060,80
>>> Lat1
'60'
>>> long1
'80'

Here is the documentation on split:

https://docs.python.org/3/library/stdtypes.html#str.split

Upvotes: 2

Related Questions