0
How do I devide natural numbers by values in a tuple?
I have this assignment and am not sure how to proceed: 'Write a program that creates a list of natural numbers from 1 to 100, divisible by values contained in the tuple, e.g: (2,3,7). Print the list on the screen.' Could someone help me? I got only to the point of finding the natural numbers, but dividing them through a tuple is a problem. Do I make a list of the primes and iterate sort of through that? Or do I iterate through the tuple?
3 Respostas
+ 3
Weronika Pucek ,
#we need to use 2 nested for loops:
we need a tuple of divisors
use the outer loop to iterate through a range from 1 upto 100 including
use the inner loop to iterate through the tuple
check if division of the number % divisor results to 0
if yes: print that number
+ 2
Using map or filter built-in functions is useful
+ 2
from natural numbers i = 1 to n
From tuple numbers j
add to list i if i%j , if i is not in list
Print list.
Just iterate to range 1 to n, and innerly through tuple, do add. If you don't know how loop works, then go through loops lesson. Then give a try..
If not work then share your try...
Hope it helps..