自動檢測Alice成績,并保存舊成績輸出新成績
d = {
? ? 'Alice': 45,
? ? 'Bob': 60,
? ? 'Candy': 75,
? ? 'David': 86,
? ? 'Ellena': 49
}
if 'Alice' in d.keys():
? ? print('Alice old score is ' + str(d['Alice']))
? ? d['Alice'] = 60
? ? print('Alice new score is ' + str(d['Alice']))
2022-06-24
2021-03-18
d = {
? ? 'Bob': 60,
? ? 'Candy': 75,
? ? 'Dadid':86,
? ? 'Ellena':49
}
if d.get('Alice') != None:
? ? alice = d.get('Alice')
? ? print(d.get('Alice'))
? ? d['Alice']=60
? ? print(d)
else:
? ? d['Alice']=60
? 這段代碼怎么什么都打印不出來,麻煩各位同學(xué)幫忙看下!
2021-01-31
# Enter a code
d = {
? ? 'Alice': [45],
? ? 'Bob': 60,
? ? 'Candy': 75,
? ? 'David': 86,
? ? 'Ellena': 49
}
if 'Alice' in d:
? ? print('Alice old score is ' + str(d.get('Alice')[0:len(d.get('Alice'))]))
? ? d['Alice'].append(60)
? ? print('Alice new score is ' + str(d['Alice'][-1]))