In: Computer Science
using python 3
2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000.
3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False.
4. In your main Python program write a for loop that counts from 1 to 1000 and calls this YesNo function inside the for loop and will print "The number xx is divisible by both 2 and 7 but not 70, or that are divisible by 57" if the YesNo function returns True. Otherwise it prints nothing. Note the print statement also prints the number where the xx is above.
SOLUTION 2:
NOTE: Explanation is in the code
##we need to check the numbers that are divisible till 1000 we need
to loop till 1000 so we have kept as the range(1,1000)
for i in range(1,1000):
##to check if a number is divisible by another number we need to
check the remainder if the remainder is zero then that number is
divisible
##if remainder is not zero then it is not divisible
if((i%2==0 and i%7==0 and i%70!=0) or i%57==0):
print("The number ",i,"is divisible by both 2 and 7 but not 70, or
that are divisible by 57" )
CODE IMAGE:
OUTPUT:
SOLUTION 3:
##defining a function which takes number and return true or
false
def YesNo(num):
##to check if a number is divisible by other number we need to
check the remainder if remainder is zero then that number is
divisible
##if remainder is not zero then it is not divisible
if((num%2==0 and num%7==0 and num%70!=0) or num%57==0):
return True
else:
return False
##call the function
print(" Is Number 240 is divisible by both 2 and 7 but not 70, or
that are divisible by 57 ",YesNo(240))
CODE IMAGE:
SOLUTION 4:
##defining a function which takes number and return true or
false
def YesNo(num):
##to check if a number is divisible by other number we need to
check the remainder if remainder is zero then that number is
divisible
##if remainder is not zero then it is not divisible
if((num%2==0 and num%7==0 and num%70!=0) or num%57==0):
return True
else:
return False
##we need to check the numbers that are divisible till 1000 we need
to loop till 1000 so we have kept as range(1,1000)
for i in range(1,1000):
##call the function
if(YesNo(i)):
print("The number ",i," is divisible by both 2 and 7 but not 70, or
that are divisible by 57 ")
CODE IMAGE:
OUTPUT: