16Multiple lists


#1

list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
# Add your code here!
print max(a,b)

Is max a better choice?
but the hint is: Use an if statement to compare the two and print whichever is larger.


#2

If you want to go with the hint, you could do

for a,b in zip(list_a, list_b):

if a >= b:
print a
else:
print b

Excuse the whitespace, I don't think it lets me indent

Otherwise, yes,
print max(a,b)

does work as well and is much conciser...but for learning purposes :wink:


#3

yeah, that's right .thank you Sam . :grin:


#4

I'd say max() is more of a programmer's choice, since it takes the less space :wink: Good thought


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.