Commit dc8ab699 by BellCodeEditor

auto save

parent 257a3409
Showing with 10 additions and 6 deletions
...@@ -5,8 +5,12 @@ score = {'悟空': student1, '诺依': student2, '小贝': student3} ...@@ -5,8 +5,12 @@ score = {'悟空': student1, '诺依': student2, '小贝': student3}
# 问询处 # 问询处
name = input("名字:") # input()方法询问名字并赋值给变量name name = input("名字:") # input()方法询问名字并赋值给变量name
info=score[name] # 字典名score[name]赋值给变量info print("*" * 30) # 打印出30个*
# for循环对字典进行遍历,将保存的分数以键值对的形式打印出来 if name in score: # if判断名字是否在字典中
for k,v in info.items(): score = score[name] # 字典中的名字赋值给变量字典名score
print(k,v) # 打印出变量k,v # for循环对字典进行遍历,将保存的分数以键值对的形式打印出来
# 查询并打印出输入的名字对应的所有科目成绩 for k,v in score.items():
\ No newline at end of file print(k,v) # 打印出变量k,v
print("*" * 30) # 打印出30个*
else: # 否则
print("查询错误,请输入正确的名字") # 打印出错误提示
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment