## CS 115 Lab 2 Introduction to Math Operators and Test Cases (Individual)

### 50 Points

Due Sunday, January 28, 2018, midnight

Educational goals of this lab - verify that every student can

• begin to understand the testing process
• implementation versus design
• experimenting and documenting experiments
• input operators
• arithmetic operators
• sqrt function Because I didn't lecture on this, 5 points bonus if you do it
• difference between float and ints

INSTRUCTIONS:

(50 points) Individual Problem: Calculating drop times

To find the length of time (in seconds) that a small steel sphere would take to fall from a given height (in meters), you can use this formula. h is the height, g is the acceleration due to gravity. The formula gives the result in seconds. Use the value of 9.8 (meters per second per second) for g.

(20 points) Problem #1: Complete a test plan.

• Calculate what A., B., C and D will be. Yes, a calculator is perfectly fine to use here.
DescriptionInput
a number for height
Expected output
Normal, integer height 10 A.
Normal, float height 12.5 B.
Boundary, zero height 0 C.
Error, negative height -5 D.
• Put these answers as comments at the bottom of the program you write for Problem #2.

(30 points) Problem #2: Write the program

• Write the program in Python to do what is described above. The program needs a prolog, which should contain your name, section, email address (uky.edu).
• It should also have documentation (comments) in the code. You MUST use this design as documentation for your program. Make the design steps comments in the Python file. Put each Python code statement immediately after its design step comment.
• Here is the design.
```Purpose:   Calculate the time to fall from a given height.
Preconditions:  input height for the sphere in meters
Postconditions: output time taken to fall for the sphere, showing 3 places

Design: (Pseudocode)

Get needed data from the keyboard, height of the sphere.
Calculate the time for it to fall.
Output the time with label.

```
• The equation to use is shown above. Use the value of 9.8 meters per second per second for g. Make a variable for this. Use the exponentiation operator to write this equation. Hint: raising something to the 0.5 power gives the square root of the thing. Make sure you document your program. Use good, multi-character, meaningful identifiers. Do NOT use "h" and "g". Use the round function to show 3 decimals in the time.
• Remember that ALL programs in this class MUST have a main function "def main():" and a call to main "main()" at the bottom of the file.
• Your program's output should look like the sample run. Note that there is a blank line output between the input statement and the output statement. Note that the numbers the user types in are on the SAME LINE as the input prompt, that is, "Enter the height for the sphere: 4". Make yours do that too.

Sample Runs - each one is a separate run of the program.

```Enter the height of the sphere: 17

The time (seconds) for the sphere to fall to the ground is 1.863
```

Another Sample run

```Enter the height of the sphere: 200

The time (seconds) for the sphere to fall to the ground is 6.389
```

Another Sample run

```Enter the height of the sphere: 5000

The time (seconds) for the sphere to fall to the ground is 31.944
```

Another Sample run

```Enter the height of the sphere: 5e10

The time (seconds) for the sphere to fall to the ground is 101015.254
```
• Run your test cases to make sure that the program is correct.
• Save the program to a file called lab2.py.