python冒号错误-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])

最佳答案 你在dict的每个条目末尾都忘了一个逗号. Dicts使用花括号“{…}”

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',

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值