![](/img/trans.png)
[英]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.