Question

In: Computer Science

using python 3 2. Write a python program that finds the numbers that are divisible by...

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.

Solutions

Expert Solution

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:

OUTPUT:

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:


Related Solutions

using python 3 2. Write a python program that finds the numbers that are divisible by...
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...
Using Python, write a program that finds a root of function f(x) = x^2-4x+3 on interval...
Using Python, write a program that finds a root of function f(x) = x^2-4x+3 on interval [2,5] using bisection search method. Recall that r is a root of a function if f(r) = 0. Output the number of iterations it took your algorithm to find a root.
Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than...
Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than 1000. The program prints the resulting number. You may only use while loops. Use python language
Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than...
Write a program that counts how many Fibonacci numbers are divisible by 3 and smaller than 1000. The program prints the resulting number. You may only use while loops. Use python language
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by...
Write a C++ program that displays the numbers between 1000 and 9999, which are divisible by sum of the digits in them. For example, 2924 is divisible by (2+9+2+4 = 17). Your program should display all these possible numbers in the given range, and each number should be separated from the other by a space.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT