我一直在尝试创建一个简单的字典来定义用户输入的单词。在定义字典及其单词之后,我尝试打印输入单词的定义。出于某种原因,当我尝试运行该程序时,列表中的冒号上出现语法错误。我不确定如何解决此问题,我知道可以使用更简单的方法来解决此问题,但是我正在尝试练习使用列表。这是到目前为止的代码:
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])
您在字典中每个条目的末尾都忘记了逗号。字典使用花括号“ {...}
”
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',
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句