2013-10-13 4 views
3

사용자가 입력 한 단어를 정의하기 위해 간단한 사전을 만들려고했습니다. 사전을 정의하고 단어를 입력 한 후, 입력 된 단어의 정의를 인쇄하려고합니다. 어떤 이유로이 프로그램을 실행하려고하면 목록의 콜론에 구문 오류가 있습니다. 나는이 문제를 해결하는 방법을 잘 모르겠다. 나는 이것을하기위한 더 쉬운 방법이 있음을 알고 있지만 목록을 사용하여 연습하려고하고있다.Python - 목록의 콜론 구문 오류

사전

dic1 = [ 
    'bug':'A broken piece of code that causes a program to stop functioning' 
    'string':'A piece of text' 
    'integer':'A whole number' 
    'float':'A decimal number' 
    'function':'A block of organized and clean code that performs a task/action' 
    'syntax':'A set of rules that says how a program will be coded'  
    ] 

q = input("What coding related word do you want defined?") 
if q in dic1: 
    print(dic1[q]) 

답변

7

당신은 DICT의 각 항목의 끝 부분에 쉼표를 잊었 : 다음은 지금까지 코드입니다. 딕 트는 중괄호를 사용합니다. "{...}"

dic1 = { 
    'bug':'A broken piece of code that causes a program to stop functioning', 
    'string':'A piece of text', 
    'integer':'A whole number', 
    'float':'A decimal number', 
    'function':'A block of organized and clean code that performs a task/action', 
    'syntax':'A set of rules that says how a program will be coded',  
    } 
+0

고마워요! : D 나는 그것이 내가 누락되었다는 것이 단순 할 것이라는 것을 알았다. – Harry