16/19 - what is wrong here?

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):
if a>=b:
print list_a
else:
print list_b

1 Like

You probably do not want to print the whole list just the iterator you are on.

for a, b in zip(list_a, list_b):
    if a > b:
        print a
    elif b > a:
        print b
    elif a == b:
        print 'Equal'
4 Likes

Try this:
list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]
print zip(list_a, list_b)
for a, b in zip(list_a, list_b):
# Add your code here!
if (a > b):
print a
else:
print b

3 Likes

Try this:

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):
    print max(a,b)
5 Likes

This is my code and it worked;
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!
if a > b:
print a
elif b > a:
print b
else:
print b

1 Like

this worked for me:

if a > b:
    print a
else:
    print b

I don’t understand!!! Someone can explain, please?

Here is the code that I used:

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!
if a > b:
print a
else:
print b

it gave me:

3
9
17
15
30
None

The instructions said:
Compare each pair of elements and print the larger of the two.

The larger is list b, why it printed the elements on list_a ???

Even with the wrong aswers it allowed me to go ahead…

You did it correctly, the instructions mean compare the numbers in the lists and print which one is bigger. So, 3 > 2, print 3. 9 > 4, print 9 etc. You were not asked to print the longer list.

3 Likes

This was the 1st approach I had…

this is where i was confused too. then i read it again, it made sense