2025年12月电子学会青少年软件编程(Python四级)等级考试试卷
客观题
四级
2025
2026-01-16 13:04:11
117次
2025年12月电子学会青少年软件编程(Python四级)等级考试试卷
客观题
四级
2025
2026-01-16 13:04:11
117次
一、单选题
19.
小明正在用Python编写一个“魔法数字盒”程序。这个数字盒有一个特殊功能:每次按下按钮时,数字会根据内部规则变化。以下是程序的一部分代码,如果小明连续按下按钮两次,屏幕上会显示什么数字?( )
def magic_box(): num = 0 # 初始数字是0 def press_button(): nonlocal num num += 1 # 每次按下按钮,数字加1 return num return press_button button = magic_box() print(button()) # 第一次按下按钮 print(button()) # 第二次按下按钮
| A. 1 1 |
B. 1 2 |
| C. 0 1 |
D. 0 0 |
【知识点】 电子学会Python四级
