50 points

__Educational goals of this lab - verify that every student can__

- Understand the testing process
- Translate algebraic equations into Python expressions
- Use a function and a constant (pi) from the math library

Submit your file with this link. Use the Lab 3 and "Code" menu choices.

__INSTRUCTIONS:__

A pendulum is a weight suspended from a pivot so that it can swing freely. When a pendulum moves back and forth (oscillates), it takes a certain amount of time to move from the highest point on the left to the highest point on the right. This time is called its period. Pendulums have been used for scientific research since the 1600's.

References: Wikipedia page on Pendulum

pendulum period calculator

**Test Plan (12 points)** Make sure your program gives these results.
Part of the grading process will be to run your program with these cases.
Every test case that your program gives the correct answer for is worth 4 points.

The input is the length of the pendulum (in meters). The expected outputs are the period (time in minutes and seconds that the pendulum takes to swing back and forth) on three different planets, the Earth, Mars and Jupiter.

Description | Input | Expected Outputs |
---|---|---|

Normal case | 200 | 0 min,28.385 sec, 0 min,46.032 sec, 0 min,18.48 sec |

Boundary case, | 0 | 0 min, 0 sec, 0 min, 0 sec, 0 min, 0 sec |

Error case, length < 0 | -5 | 0 min,2.007 sec, 0 min,3.255 sec, 0 min,1.307 sec |

**Sample Run:**

Period of a pendulum How long is the pendulum (m)? 200 The period is 28.385 seconds or 0.0 minutes and 28.385 seconds on Earth The period is 46.032 seconds or 0.0 minutes and 46.032 seconds on Mars The period is 18.48 seconds or 0.0 minutes and 18.48 seconds on Jupiter

**Another Sample Run:**

Period of a pendulum How long is the pendulum (m)? 3100 The period is 111.75 seconds or 1.0 minutes and 51.75 seconds on Earth The period is 181.227 seconds or 3.0 minutes and 1.227 seconds on Mars The period is 72.756 seconds or 1.0 minutes and 12.756 seconds on Jupiter

**Another Sample Run:**

Period of a pendulum How long is the pendulum (m)? -5 illegal length, length set to 1 The period is 2.007 seconds or 0.0 minutes and 2.007 seconds on Earth The period is 3.255 seconds or 0.0 minutes and 3.255 seconds on Mars The period is 1.307 seconds or 0.0 minutes and 1.307 seconds on Jupiter

**Design given**

# supply program prolog - fill this in! # include purpose, pre-conditions (inputs) and post-conditions (outputs) # gravity = 9.8 m/sec^2 on Earth # gravity = 3.7263 m/sec^2 on Mars # gravity = 23.12 m/sec^2 on Jupiter # main function # 1. Display introductory message # 2. get input from user of pendulum length # 3. if length is negative # give message, set length to 1 # 4. set gravity to Earth's value # 5. calculate the period for that length # 6. output the result in seconds and minutes and seconds # 7. set gravity to Mars' value # 8. calculate the period for that length # 9. output the result in seconds and minutes and seconds # 10. set gravity to Jupiter's value # 11. calculate the period for that length # 12. output the result in seconds and minutes and seconds

The formula for the period of a pendulum (seconds) given the length of the pendulum (meters) and the acceleration due to gravity (meters per second squared) is .

**Implement the design (38 points)**
Individually write a Python program to implement the design.
Write your Python code between the commented lines of the design.
Make sure you eliminate any syntax and semantics errors.
Here is where test cases come in handy!
Verify that it does come out with the correct answers.

There are some specifications about how your program should be written.

- This program uses an input; prompt the user for it.
- Use assignment statements to perform the calculations, not output statements.
- Use the math library's predefined constant pi and function sqrt in this formula.
- You must use // and % for converting seconds to minutes and seconds.
- Your code must be documented. You must use meaningful variable names, NOT single-letter names. Use the design given for internal documentation. You must have a header as usual.
- Make sure you format the lines of the output as described above. The decorations, line breaks and the punctuation should be exactly as shown.
- Note the types of data being output. Your program must match those. The floats must be rounded to 3 decimal places.

Remember to submit your program source (pendulum.py) with the link at the top of the page.