Questions: Write a program to test the functions described in Exercises 11 and 14 of this chapter. Instructions for Exercise 11 and Exercise 14 have been posted below for your convenience. Exercise 11 Write the definition of a function that takes as input a char value, and returns true if the character is a whitespace character; otherwise it returns false. If the character is a whitespace character, output the following message: The character you entered is a whitespace character, otherwise output: The character you entered is not a whitespace character. Exercise 14 Write the definition of a function that takes as input three numbers. The function returns true if the floor of the product of the first two numbers equals the floor of the third number; otherwise it returns false. (Assume that the three numbers are of type double.) Output the appropriate message: The product of the first two numbers is not equal to the floor of the third number or The product of the first two numbers is equal to the floor of the third number

Write a program to test the functions described in Exercises 11 and 14 of this chapter.
Instructions for Exercise 11 and Exercise 14 have been posted below for your convenience.
Exercise 11
Write the definition of a function that takes as input a char value, and returns true if the character is a whitespace character; otherwise it returns false.

If the character is a whitespace character, output the following message: The character you entered is a whitespace character, otherwise output: The character you entered is not a whitespace character.

Exercise 14
Write the definition of a function that takes as input three numbers. The function returns true if the floor of the product of the first two numbers equals the floor of the third number; otherwise it returns false. (Assume that the three numbers are of type double.) Output the appropriate message: The product of the first two numbers is not equal to the floor of the third number
or
The product of the first two numbers is equal to the floor of the third number
Transcript text: Write a program to test the functions described in Exercises 11 and 14 of this chapter. Instructions for Exercise 11 and Exercise 14 have been posted below for your convenience. Exercise 11 Write the definition of a function that takes as input a char value, and returns true if the character is a whitespace character; otherwise it returns false. If the character is a whitespace character, output the following message: The character you entered is a whitespace character, otherwise output: The character you entered is not a whitespace character. Exercise 14 Write the definition of a function that takes as input three numbers. The function returns true if the floor of the product of the first two numbers equals the floor of the third number; otherwise it returns false. (Assume that the three numbers are of type double.) Output the appropriate message: The product of the first two numbers is not equal to the floor of the third number or The product of the first two numbers is equal to the floor of the third number
failed

Solution

failed
failed

To address the question, we need to write a program that tests the functions described in Exercises 11 and 14. Below, I will provide the implementation of these functions in Python, along with a simple test program to demonstrate their functionality.

Exercise 11: Function to Check for Whitespace Character
def is_whitespace(char):
    """
    This function takes a character as input and returns True if it is a whitespace character,
    otherwise returns False. It also prints a message based on the result.
    """
    if char.isspace():
        print("The character you entered is a whitespace character.")
        return True
    else:
        print("The character you entered is not a whitespace character.")
        return False

# Test the function
print(is_whitespace(' '))  # Should return True and print the whitespace message
print(is_whitespace('a'))  # Should return False and print the non-whitespace message
Exercise 14: Function to Compare Product and Floor
import math

def compare_product_and_floor(num1, num2, num3):
    """
    This function takes three numbers as input. It returns True if the floor of the product
    of the first two numbers equals the floor of the third number, otherwise returns False.
    It also prints a message based on the result.
    """
    product_floor = math.floor(num1 * num2)
    third_floor = math.floor(num3)
    
    if product_floor == third_floor:
        print("The product of the first two numbers is equal to the floor of the third number.")
        return True
    else:
        print("The product of the first two numbers is not equal to the floor of the third number.")
        return False

# Test the function
print(compare_product_and_floor(2.5, 4.0, 10.0))  # Should return True and print the equal message
print(compare_product_and_floor(2.5, 4.0, 9.9))   # Should return False and print the not equal message
Summary
  • The is_whitespace function checks if a given character is a whitespace character and prints an appropriate message.
  • The compare_product_and_floor function checks if the floor of the product of two numbers equals the floor of a third number and prints an appropriate message.
  • Both functions are tested with example inputs to demonstrate their functionality.
Was this solution helpful?
failed
Unhelpful
failed
Helpful