For an assignment I need to do these two exercises:
create a list that includes multiplying each number from 1 to 9 (included) by 100, only if it divides with 2 with no remainder.
create a list that includes multiplying each number from 1 to 9 (included) by 100, only if it divides with 2 with no remainder.if there is a remainder leave the number as is, don't multiply by 100.
Answer 1 worked:
list_1 = [num * 100 for (num) in range(1,10) if num % 2 == 0]
print (list_1)
But why doesn't the answer for exercise 2 work?:
list_1 = [num * 100 for (num) in range(1,10) if num % 2 == 0 else num]
print (list_1)