INFO1110 Week 7 每周题库 · Functions 函数、作用域与返回值
Week 7 精选练习:函数定义、参数、作用域、返回值与引用。Curated practice on functions, scope, return values and references.
What is the best description of the behaviour of the following function?def check(xs: list, val) -> int: count = 0 for x in xs: if x == val: count += 1 return count
What is the value of result after only the following code is run?result = [] for x in range(6): if x == 2 or 3: result.append(x)
What is the value of count after the following code is run?count = 0 for x in 'Hello World': if x == 'l' or x == 'o': count += 1
Consider the function foo defined below. What type of value does foo return?def foo(n: int): """Precondition: n > 0""" total = 0 for i in range(n): total += i print(total)
What error (if any) will the following code produce?def greet(name): global name return 'Hello, ' + name greet('Alice')
你的进度
已练 0 / 40 · 正确率 0%