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