Question: Write code for a function that takes two arguments named a and b. The function returns a true value if b is divisible by a

Write code for a function that takes two arguments named a and b. The function returns a true value if b is divisible by a and a false value otherwise. For example, 10 is divisible by 5, but 10 is not divisible by 3.

Write code for a function named factors that takes in two variables, an integer named num and a list of integers named potentials. Using a for loop, use the function of the previous question, to check if each number in potentials is a factor of num. When an element of potentials is not a factor, return a value representing false, otherwise if all the elements of potentials are factors of num, the function returns a value representing true.

Write code for function main, which does the following:

  1. get one integer value from the user.
  2. using a loop that runs as long as a variable named stop is not 0. The loop gets integers from the user and add those to a list named factors as long as the user does not enter 0. If the input is 0 do not ad it to the list and assign variable stop to 0.
  3. If the result of passing the input of step 1 and the list of step 2, to function factors is a true value, write all the numbers in the list, each on its own line to a file. Ask the user for the filename.
  4. If step 3 results in a false value, print the message "numbers are not factors".
  5. Add exception handling to the code above (think of where to place it) so that any error from writing the data to the file are handled by printing the message "data writing failed", otherwise print "data writing succeeded".

Call main at the end.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!