1. Demonstrate your functions knowledge in program5_1.py by coding two functions that calculate the surface area of a rectangular prism (a box). One function must return the surface area to main() for printing. The other void function must print the surface area when called in main(). Both functions should take the three dimensions of the box as arguments. Prompt the user for these dimensions in main(). Express the surface area accurate to one decimal place. See Sample Output. IMPORTANT: In one or more comments, clearly explain how you would decide when to use one function over the other in an application.

Sample Output

Enter side 1 2.5
Enter side 2 3.5
Enter side 3 4.5
Using value-returning function...
Surface area: 71.5
Now with void function...
Surface area: 71.5

2. Write a program named program5_2.py that prompts the user to enter an integer (maximum 20). If the user complies, main() should call a value-returning function named randnums with this value as its sole argument. The randnums function should use the argument to generate an equivalent number of random integers (all from 1-9). These integers should be printed all on one line separated by spaces. The randnums function should also determine the total of the random numbers and return this total to main() for printing. See Sample Output. If the user does not comply with the input request, the program should print a corrective message and randnums should not be called.

Sample Output (2 runs)

How many random integers (max 20)? 12
5 9 7 7 9 8 8 2 5 5 8 7
Integers total is 80
How many random integers (max 20)? 33
Bad input. Maximum input is 20

3. Create a custom Python module named arithmetic.py. This module must contain four functions as follows:

  • total that takes two numbers as arguments and prints their sum accurate to one decimal place.
  • difference that takes two numbers as arguments and prints their positive difference accurate to one decimal place.
  • product that takes two numbers as arguments and returns their product.
  • quotient that takes two numbers as arguments and returns the quotient of the first argument divided by the second argument.

Write a program named program5_3.py that imports the arithmetic module, prompts the user to enter two numbers, and tests all four methods in the module.The numbers entered should be type float. The main function should print the values returned by the product and quotient functions accurate to two decimal places.

SAMPLE OUTPUT

Enter a number 2.5
Enter another number 5
The total is 7.5
The difference is 2.5
The product is 12.50
The quotient is 0.50
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.