Question

In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and...

In Python

5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and n2. Using a single list comprehension to make a list of all of the numbers in the range 1..N that are either divisible by n1 or n2, where n1 and n2 can be any positive integers. After creating the list, your code should print out the following 2 lines: “We are printing all numbers from 1 to that are divisible by or ” “These values are : ” Finally you should return the new list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def listComprehensionDivisors (N,n1,n2):
    res = [i for i in range(1,N+1) if (i%n1==0) or (i%n2==0)]
    print("We are printing all numbers from 1 to that are divisible by",n1,"or",n2)
    print("These values are :",res)

# Testing
listComprehensionDivisors(20,3,5)

Add a comment
Know the answer?
Add Answer to:
In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and...
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