B. Math Utilities: Create a file called math_utilities.py where you will write several usefulmath functions. The end result will be a module you can use in the future. Note that the first two canbe copied and pasted from your in-class assignmentImplement these functions in vour moduleis_divisible(a, b)- returns True if a is divisible by b, otherwise False.is_divisible_either(a, b)- returns True if a is divisible by b or bis divisible by a, otherwise False.is prime(num) - returns True if the number is prime, otherwise False.absolute_equals(a, b) - returns True if Ja is equal to lb, otherwise Falseis_within(a, b, epsilon)- returns True if the absolute difference between a and b is less thanepsilonWrite a program called test math_utilties.py that calls each of these with different tests. (Youmay skip the tests for the first two since we did them in class.)Here are some values to tryis_prime: 7-True, 12- False , 13- True, 19 True, 22 False, 35- Falseabsolute_equals: 7,8- False; 7,-7True; -6,6 True; -3,-3-True; 12,12- True; -9,8-Falseis_within: 5,12,6-False; 5,12,7-False; 5,12,8True; 12,5,7- False; 12,5,8True;3.333,3.33333,0.001 True; 3.333,3.33333,0.0001FalseYou will upload these two .py files to Canvas as part of your assignment submission: math utilities.py,test math_utilities.py.Shoot a screenshot of your source code for math_utilties.py and paste it hereShoot a screenshot of your source code for test_math_utilities.py and paste it here.Shoot a screenshot of your Python Shell showing the output and paste it here.

Question
Asked Sep 19, 2019
2 views

please solve this in python 

////////////////

////////////////

////////////////

////////////////

B. Math Utilities: Create a file called math_utilities.py where you will write several useful
math functions. The end result will be a module you can use in the future. Note that the first two can
be copied and pasted from your in-class assignment
Implement these functions in vour module
is_divisible(a, b)- returns True if a is divisible by b, otherwise False.
is_divisible_either(a, b)- returns True if a is divisible by b or bis divisible by a, otherwise False.
is prime(num) - returns True if the number is prime, otherwise False.
absolute_equals(a, b) - returns True if Ja is equal to lb, otherwise False
is_within(a, b, epsilon)- returns True if the absolute difference between a and b is less than
epsilon
Write a program called test math_utilties.py that calls each of these with different tests. (You
may skip the tests for the first two since we did them in class.)
Here are some values to try
is_prime: 7-True, 12- False , 13- True, 19 True, 22 False, 35- False
absolute_equals: 7,8- False; 7,-7True; -6,6 True; -3,-3-True; 12,12- True; -9,8-False
is_within: 5,12,6-False; 5,12,7-False; 5,12,8True; 12,5,7- False; 12,5,8True;
3.333,3.33333,0.001 True; 3.333,3.33333,0.0001False
You will upload these two .py files to Canvas as part of your assignment submission: math utilities.py,
test math_utilities.py.
Shoot a screenshot of your source code for math_utilties.py and paste it here
Shoot a screenshot of your source code for test_math_utilities.py and paste it here.
Shoot a screenshot of your Python Shell showing the output and paste it here.
help_outline

Image Transcriptionclose

B. Math Utilities: Create a file called math_utilities.py where you will write several useful math functions. The end result will be a module you can use in the future. Note that the first two can be copied and pasted from your in-class assignment Implement these functions in vour module is_divisible(a, b)- returns True if a is divisible by b, otherwise False. is_divisible_either(a, b)- returns True if a is divisible by b or bis divisible by a, otherwise False. is prime(num) - returns True if the number is prime, otherwise False. absolute_equals(a, b) - returns True if Ja is equal to lb, otherwise False is_within(a, b, epsilon)- returns True if the absolute difference between a and b is less than epsilon Write a program called test math_utilties.py that calls each of these with different tests. (You may skip the tests for the first two since we did them in class.) Here are some values to try is_prime: 7-True, 12- False , 13- True, 19 True, 22 False, 35- False absolute_equals: 7,8- False; 7,-7True; -6,6 True; -3,-3-True; 12,12- True; -9,8-False is_within: 5,12,6-False; 5,12,7-False; 5,12,8True; 12,5,7- False; 12,5,8True; 3.333,3.33333,0.001 True; 3.333,3.33333,0.0001False You will upload these two .py files to Canvas as part of your assignment submission: math utilities.py, test math_utilities.py. Shoot a screenshot of your source code for math_utilties.py and paste it here Shoot a screenshot of your source code for test_math_utilities.py and paste it here. Shoot a screenshot of your Python Shell showing the output and paste it here.

fullscreen
check_circle

Expert Answer

Step 1

A python program to display the boolean values for the given functions is provided below;

Program code:

File name: “math_utilities.py

#Define the function "is_divisible(a,b)"

def is_divisible(a,b):

    if(a%b==0):

        return True

    else:

        return False

#Define the function "is_divisible_either(a,b)"

def is_divisible_either(a,b):

    if(a%b==0 or b%a==0):

        return True

    else:

        return False

#Define the function "is_prime(num)"

def is_prime(num):

    if num > 1:

        for i in range(2, num):

            if (num % i) == 0:

                return False

                break

        else:

            return True

    else:

        return False

#Define the function "absolute_equals(a,b)"

def absolute_equals(a,b):

    if(abs(a)==abs(b)):

        return True

    else:

        return False

#Define the function "is_within(a,b,epsilon)"

def is_within(a,b,epsilon):

    if(a>b):

        difference=a-b

        if(difference<epsilon):

            return True

        else:

            return False

    else:

        difference=b-a

        if(difference<epsilon):

            return True

        else:

            return False

#Print the string

print("Enter the value for a and b")

#Get the input for a and b from the user

a=int(input())

b=int(input())

#Print the boolean value return from the function "is_divisible(a,b)"

print ("is_divisible(",a,",",b,"): ",is_divisible(a,b))

#Print the boolean value return from the function "is_divisible_either(a,b)"

print ("is_divisible_either(",a,",",b,"): ",is_divisible_either(a,b))

#Print the boolean value return from the function "absolute_equals(a,b)"

print ("absolute_equals(",a,",",b,"): ",absolute_equals(a,b))

#Print the string

print ("Enter the number to find prime")

#Get the input to check prime number

num=int(input())

#Print the boolean value return from the function "is_prime(num)"

print ("is_prime(",num,"): ",is_prime(num))

#Print the string

print ("Enter the value for epsilon")

#Get the input for epsilon

epsilon=int(input())

#Print the boolean value return from the function "is_within(a,b,epsilon)"

print ("is_within(",a,",",b,",",epsilon,"): ",is_within(a,b,epsilon))

Step 2

Explanation:

  • The functions given in the question have been defined with the keyword “def”.
  • The statements inside the body are provided with the proper indentation and syntax.
  • The inputs to perform the given functions are get from the user through keyboard using “input()” function.
  • The appropriate function is called and the result is printed using “print” statement.

Screenshot of program #1:

Python 3.4.1: math_utilities.py - C:/Users/304074/Deskto p/math_utilities.py
File Edit Format Run Options Windows Help
#Define the function "is divisible (a,b)"
def is divisible (a,b)
if (a%b0)
return True
else:
return False
#Define the function "is divisible either (a,b)"
def is divisible either (a,b)
if (atb0 or bla-=0)
return True
else:
return False
#Define the function "is prime (num)
def is_prime (num)
:
if num >
1:
for i in range (2, num):
if (num i
0:
return False
break
else
return True
else:
return False
help_outline

Image Transcriptionclose

Python 3.4.1: math_utilities.py - C:/Users/304074/Deskto p/math_utilities.py File Edit Format Run Options Windows Help #Define the function "is divisible (a,b)" def is divisible (a,b) if (a%b0) return True else: return False #Define the function "is divisible either (a,b)" def is divisible either (a,b) if (atb0 or bla-=0) return True else: return False #Define the function "is prime (num) def is_prime (num) : if num > 1: for i in range (2, num): if (num i 0: return False break else return True else: return False

fullscreen
Step 3

Screenshot of program #2...

Define the function "absolute_equals (a,b)"
def absolute_equals (a,b)
if (abs (a)abs (b))
return True
else:
return False
Define the function "is_within (a, b, epsilon)
def is within (a,b, epsilon)
if (a>b)
difference-a-b
if (difference<epsilon)
return True
else:
return False
else
differenceb-a
if (difference<epsilon)
return True
else:
return False
#Print the string
print ("Enter the value for a and b")
#Get the input for a and b from the user
a-int (input ()
b-int (input ()
help_outline

Image Transcriptionclose

Define the function "absolute_equals (a,b)" def absolute_equals (a,b) if (abs (a)abs (b)) return True else: return False Define the function "is_within (a, b, epsilon) def is within (a,b, epsilon) if (a>b) difference-a-b if (difference<epsilon) return True else: return False else differenceb-a if (difference<epsilon) return True else: return False #Print the string print ("Enter the value for a and b") #Get the input for a and b from the user a-int (input () b-int (input ()

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: I don't want the answer, but can you please help me understand what they are asking?  I am having di...

A: Program code:

question_answer

Q: Using the following truth table, write the equivalent Boolean equations in Sum of Product and Produc...

A: Simplification of Sum Of Products (SOP):The truth table of the SOP is as follows

question_answer

Q: Attached Files:  getRandomLib.h: // This library provides a few helpful functions to return rand...

A: Program Instructions:Include the necessary header files.Print hello message and as for a response.De...

question_answer

Q: Use Java 5-1) (Count positive and negative numbers and compute the average of numbers) Write a progr...

A: Note: The below program has been complied and executed in NetBeans IDE 8.2

question_answer

Q: Hi, please do you help with questions of Python? If so, I need help with the following: Write a prog...

A: Program Instructions:Use range() to print from 1 to 25.Use end in print() function to print the valu...

question_answer

Q: List the octal and hexadecimal numbers from 1410 to 3210. Using A and B for the last two digits, lis...

A: Answer:Listing octal values from 1410 to 3210:Divide 14 by 8 (octal number) giving 1 remainder 61 is...

question_answer

Q: how to write a function in python 3 that reads a txt file which includes three number (each line has...

A: AlgorithimStartOpen a file in read modeRead a line from file and store the number in variable aRead ...

question_answer

Q: 12 4x)x,is an another form of representation of fuzzy set. A, (x) /x, is an another form of represen...

A: A fuzzy set is a pair X, m(A)) where X is a Universal set and mA) is a membership function or degree...

question_answer

Q: Assume that a computer architect has already designed 6 two-address and 24 zero-address instructions...

A: Given:Instruction length = 11 bits = 211 = 2048 bitsAddress register size = 4 bits5 two-address inst...