CMPT 120 LECTURE MIDTERM 2 SOLUTIONS

For examples average 00 average1 2 3 20 def

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (y == x): return True return False page 3 14. Write the function, average(lnums), which returns the average of the list of numbers contained in the list called lnums. Be careful with the empty list of numbers. For examples: average() = 0.0 average([1, 2, 3]) = 2.0 def average3(s): n = len(s) if (n == 0): return 0.0 sum = 0.0 for x in s: sum = sum + float(x) return sum / len(s) 15. What is the output of this Python program? s = "" i = 64 while (i > 0): s =...
View Full Document

This document was uploaded on 03/18/2014 for the course CMPT 120 at Simon Fraser.

Ask a homework question - tutors are online