Lecture 8 — Exercises¶
Solutions to the problems below must be sent to Submitty for grading. A separate file must be submitted for each problem. These must be submitted by 4 pm on Tuesday, September 28th.
What is the output from the following code. Note that we did not cover all of these techniques in class, so you might need to do some exploration on your own.
def hmmm( x ): if x > x: return (x, x) else: return x s = ('a', 'b') t = (1, 2, 3) u = (4, 5, 2) print( t + u ) print( t+u ) print( s * t ) print( hmmm(u) ) print( hmmm( (5, 2, 3) ))
Write a function called
add_tuplesthat takes three tuples, each with two values, and returns a single tuple with two values containing the sum of the values in the tuples. Test your function with the following calls:
print(add_tuples( (1,4), (8,3), (14,0) )) print(add_tuples( (3,2), (11,1), (-2,6) ))
Note that these two lines of code should be at the bottom of your program. This should output
(23, 7) (12, 9)