Functions & Scope · Question 5 · Easy

The function below collects any number of marks using *marks. What is printed?

def average(*marks):
    return sum(marks) / len(marks)

print(average(60, 70, 80))
  1. 70
  2. 70.0
  3. 210
  4. TypeError
Answer and explanation

Answer: B. 70.0

Explanation: *marks packs the three arguments into the tuple (60, 70, 80). The sum is 210 and 210 / 3 uses true division, which always gives a float: 70.0.

Previous: A lambda is given a default value for its second parameter. What does this… · Next: A function assigns to a name that also exists at module level. What does this…

Practise functions & scope

Try a fresh set of functions & scope questions with an explanation after every answer, free and without signing up: Functions & Scope practice. Or sit a full placement mock test.

More functions & scope questions

More python practice

Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge