题目
题目

Programming Programming In-class Test- Part 1 Programming Programming In-class Test- Part 1

多项选择题

This question is worth 3 marks. Don't guess, you will be penalised 3/4 of a mark for an incorrect answer. You won't be penalised for leaving your answer blank.Consider the following Python code:def func_two(dict_one): x = None y = None for key, value in dict_one.items(): if x: if value > x: x = value y = key else: x = value y = key return y def func_one(input_str): dict_one = {} for i in input_str: if i in dict_one: dict_one[i] += 1 else: dict_one[i] = 1 res = func_two(dict_one) return res if __name__ == "__main__": print (func_one("python programming")) print (func_one("Hello World")) What does the code output?

选项
A.p l
B.m l
C.2 3
D.6 11 5 5
E.None of the above
查看解析

查看解析

标准答案
Please login to view
思路分析
We start by restating what the code does and what outputs are being asked to determine. - The code defines func_two(dict_one) which iterates over dict_one.items() with variables key and value. It uses a variable x initialized to None and a variable y initialized to None. The logic inside the loop is: if x is truthy, then if value > x, set x = value and y = key; else set x = value and y = key. If x is not truthy (i.e., None or 0), it goes to the else and sets x = value and y = key. After the loop, func_two returns y. - func_one(input_str) builds a dictionary dict_one countin......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!