LearnFrenzy
Sign in Take a free test

Tuples · Predict the Output · Question 7

A function that returns three values Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

What is the output of the following Python program?

main.py
def stats(nums):
    return min(nums), max(nums), sum(nums) / len(nums)

r = stats([2, 8, 5])
print(r, type(r).__name__)
lo, hi, avg = r
print(lo, hi, avg)
  • A [2, 8, 5.0] list 2 8 5.0
  • B (2, 8, 5.0) tuple 2 8 5.0 Correct
  • C 2 8 5.0 tuple 2 8 5.0
  • D (2, 8, 5) tuple 2 8 5
Correct Answer: Option B

The return statement packs one tuple. / always gives a float, so the average is 5.0.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links