Question

Write a list comprehension that generates all the odd numbers between 1 and 50 (i.e., [1,...

Write a list comprehension that generates all the odd numbers between 1 and 50 (i.e., [1, 3, 5, ..49])

for python programming

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

li=list(range(1,50)) #taking the list elements and storing it in li
print(li)
print('odd numbers in the list')
for l in li:
    if l % 2 != 0: #running the loop to check the odd numbers
    
        print(l, end = " ")

Thank you.

Give a like for appreciation. Feel free to comment your doubts.

X Python 3.7.4 Shell File Edit Shell Debug Options Window Help Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [M

Add a comment
Know the answer?
Add Answer to:
Write a list comprehension that generates all the odd numbers between 1 and 50 (i.e., [1,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT