全部来自 AI 原创生成并经逐题审校的题目,带 精品 标记的为 AI 复审通过。整卷生成请去组卷。
有如下 Python 代码: class Timer: def __init__(self, name): self.name = name self.count = 0 def tick(self): self.count += 1 return self.count t1 = Timer('A') t2 = t1 t2.tick() t2.tick() t1.tick() print(t1.name, t1.count) 执行后输出的结果是( ) A. A 3 B. A 1 C. A 2 D. 程序报错
登录后查看答案
某抽签程序要随机生成一个整数编号,所有可能编号恰为 31 至 46(含端点)。已执行 `from random import randint`,应填入哪组参数? A. 31, 45 B. 31, 46 C. 32, 46 D. 31, 47
已有 UTF-8 文件“输入.txt”,内容为两行“春风 秋雨 ”;已有文件“输出.txt”,内容为“旧记录 ”。执行以下代码后,关于“输出.txt”的内容及文件关闭情况,哪项正确? with open('输入.txt', 'r', encoding='utf-8') as src: with open('输出.txt', 'w', encoding='utf-8') as dst: for line in src: dst.write(line) A. 内容为“旧记录 春风 秋雨 ”,两个文件均自动关闭 B. 内容为“春风 秋雨 ”,两个文件均自动关闭 C. 内容为“春风 秋雨 ”,只有“输入.txt”自动关闭 D. 内容为“旧记录 ”,两个文件均自动关闭
已有函数定义:def plan(dest, speed=60, *stops, **info): return (dest, speed, stops, info)。现有两次连续调用:第一次执行 plan("A城", 80, "B站", "C站", note="绕行"),第二次执行 plan("D城", "E站")。第二次调用的返回值中,speed 与 stops 的值分别是?A. speed=60,stops=("E站",) B. speed="E站",stops=() C. speed=60,stops=() D. speed="E站",stops=("E站",)
阅读代码,选择变量 r2 的值。 ```python def pack(tag, *items, memo=[], **opts): memo.append(tag) return items, memo, opts r1 = pack("甲", 3, 4, mode="静") r2 = pack("乙", 5, mode="急") ``` A. ((5,), ['乙'], {'mode': '急'}) B. ((5,), ['甲', '乙'], {'mode': '急'}) C. ((5,), ['甲', '乙'], {'mode': '静'}) D. ((5, '急'), ['甲', '乙'], {})
阅读代码,填写程序输出的整数。 ```python records = [(4, 2), (1, 3), (3, 1)] first = sorted(records, key=lambda t: t[1])[0][0] def total(n): if n == 0: return 1 return n + total(n - 1) print(total(first)) ``` 程序输出:___
阅读以下 Python 代码,填写运行后 result 的值。 ```python token = "外" def inspect(): token = "局" def mutate(): global token token = token + "全" return token before = token after = mutate() return before, after, token result = inspect() ``` result = ____
执行以下代码后,print 语句共输出 3 个数字,依次为(各数字之间用空格分隔):____。 for i in range(20, 9, -4): print(i)
执行以下 Python 代码: d = {'x': 10, 'y': 20} d['z'] = d.get('w', d['x']) 执行结束后,表达式 list(d.keys()) 的值为( ) A. ['w', 'x', 'y', 'z'] B. ['x', 'y', 'z'] C. ['x', 'y', 'z', 'w'] D. ['z', 'y', 'x']
已知元组 t = ("苔", "泉"),执行 x, y = t 后,集合 S = {x, y, x} 的值为____。
某校内平台按登记顺序建立字典:records = {'青禾': '通过', '远帆': '待审', '星桥': '通过'}。若直接访问 records['松露'] 会触发 KeyError,而 records.get('松露', '未登记') 得到默认值;再按 items() 遍历,并用字典推导式保留状态为'通过'的键值对,则所得字典为____。
执行 t = ("银", "金", "银"),(x, y, z) = t,A = set(t),B = {"金", "铜"},C = A & B 后,判断:C = {"金"},且执行交集运算使元组 t 变为 ("银", "金")。
某程序先执行以下代码: items = [8, 3, 6, 2, 9] backup = items[:] items.insert(2, 7) items.pop(1) items.sort() backup = sorted(backup, reverse=True) 执行后,items 与 backup 的值分别是什么? A. [2, 6, 7, 8, 9];[9, 8, 6, 3, 2] B. [2, 6, 7, 8, 9];[2, 3, 6, 8, 9] C. [2, 6, 8, 9];[9, 8, 6, 3, 2] D. [2, 6, 7, 8, 9];None
判断:执行 t = ('q', [8, 9]) 后,语句 s = {t} 可以正常创建集合,因为元组属于不可变类型。
判断:元组 t = ([3, 5],) 可以作为集合元素,因为元组是不可变类型。
某传感器先按递减序列读取一组校准值,再按递增序列读取一组补偿值。执行以下程序后,变量 total 的值是____。 total = 0 for x in range(14, 2, -4): total += x for x in range(1, 8, 3): total += x
阅读下列代码,最终变量 result 的值是什么? items = [] if items and items[0] == "ok": result = "甲" elif not items or items[0] == "hold": result = "乙" else: result = "丙" A. 甲 B. 乙 C. 丙 D. 程序发生 IndexError
执行以下代码后,print 语句共输出的数字依次是( )。 for i in range(2, 11, 2): print(i) A. 2 4 6 8 10 B. 2 4 6 8 C. 2 3 4 5 6 7 8 9 10 D. 4 6 8 10
设字符串 s = "mosaic"。下列哪个表达式的结果是 "ias"? A. s[2:5][::-1] B. s[2:5] C. s[-1:1:-1] D. s[1:4][::-1]
设字符串 s = "cobalt"。判断:切片表达式 s[-1:1:-2] 的结果是 "tao"。