[英]I'm trying to make a user input dictionary for extra credit in my class and I can't figure out how to properly end the program
[英]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
Lat1,long1 = input("Enter the Lat and Long of the source point separated by a comma eg 20,30").split()
默认情况下,使用split()
只会在一个空间上分割。 你问用户输入一个分开的两个条目,
,所以你最终会得到一个
ValueError: not enough values to unpack (expected 2, got 1)
要解决此问题,您需要分割要与之分割的标识符。 在这种情况下,它是一个',',因此将split
称为split(',')
:
Lat1,long1 = input("Enter the Lat and Long of the source point separated by a comma eg 20,30").split(',')
演示:
>>> 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'
这是关于拆分的文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.