【发布时间】:2021-06-11 15:46:17
【问题描述】:
- 这是普通文本。您好,我需要解决字典和条件语句列表的问题,但是我的代码没有输出 - 但也没有错误消息。这就是问题所在:
定义一个名为“dataset”的变量,其中包含以下信息:
Artist Track Plays
Dire Straits Sultans of Swing 65
Pink Floyd Comfortably Numb 23
The Smiths Cemetery Gates 15
Nick Cave & The Bad Seeds The Ship Song 36
Dire Straits Brothers in Arms 20
打印少于 25 次播放的歌曲的艺术家和曲目(标题)。每个艺术家和曲目组合都打印在单独的行上。
打印 The Smiths 和 Pink Floyd 歌曲的所有曲目标题。只打印标题是可以的,每个标题都打印在单独的行上。
打印总播放次数。这是所有 5 首歌曲的总播放次数。
到目前为止我的代码是这样的:
enter code here
dataset = [
{'Artist':'Dire Straits','Track':'Sultans of Swing','Plays':65},
{'Artist':'Pink Floyd','Track':'Comfortably Numb','Plays':23},
{'Artist':'The Smiths','Track':'Cemetry Gates','Plays':15},
{'Artist':'Nick Cave & The Bad Seeds','Track':'The Ship Song','Plays':36},
{'Artist':'Dire Straits','Track':'Brothers in Arms','Plays':20},
]
for x in dataset:
if 'Plays' in dataset > 25:
print (dataset['Artist','Track'])
'''
【问题讨论】:
标签: python dictionary conditional-statements