Question

Asked Sep 19, 2019

2 views

please solve this in python

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

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

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

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

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:**

Step 3

**Screenshot of program #2...**

Tagged in

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:

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

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...

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

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...

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...

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 ...

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...

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...