CS 115 Program 1 Time and Mass at High Speeds Fall 2017


Due Dates:
Individual Design: Wednesday, September 27, midnight
Program Source: Sunday, October 8, midnight

Assignment total points = Design (20 points) + Runs 9 test cases successfully (20 points) + Implementation correctly written (70 points) + Style and documentation (15 points) = 125 points

Submit all program materials (.py files) with the link here.

Note that there is a FAQ about program 1. Please read this! It will save you points!

Educational Goals: The educational goals of this program are that the student should use the concepts of

You are going to calculate the length of time that passes for astronauts as they travel at near light speeds. Time passes more slowly for the astronauts on a spaceship than for people on earth as the ship approaches the speed of light. The mass of an object like a spaceship increases as it moves faster, approaching the speed of light. Einstein wrote an equation that provides a factor indicating the change in time and mass based on speed, which is: where v is velocity and c is the speed of light which is approximated at 299,792,458 meters/second. The factor calculated is how much time is reduced by and how much mass is increased by. For example, at 149,896,229 meters per second (half the speed of light) the factor is 1.1547005383792517. Time's passage is reduced by that factor (division) and mass is increased by that factor (multiplication).
DestinationDistance
Alpha Centauri4.367 light years
Barnard's Star6.0 light years
Betelgeuse642.5 light years
Andromeda Galaxy 2.537 million light years

Example run: (Test Case #1)

Time Dilation

Enter velocity as a percentage of speed of light: 50.0
Ship is traveling at 50.0% of the speed of light

At this speed:
        Weight of the shuttle is 80829.03768654761 kg
        Perceived time to travel to Alpha Centauri is 3.781933 years
        Perceived time to travel to Barnard's Star is 5.196152 years
        Perceived time to travel to Betelgeuse is 556.421322 years
        Perceived time to travel to Andromeda Galaxy is 2197106.449401 years

Example run: (Test Case #2)

Time Dilation

Enter velocity as a percentage of speed of light: 0.000001
Ship is traveling at 1e-06% of the speed of light

At this speed:
        Weight of the shuttle is 70000.00000000001 kg
        Perceived time to travel to Alpha Centauri is 4.367 years
        Perceived time to travel to Barnard's Star is 6.0 years
        Perceived time to travel to Betelgeuse is 642.5 years
        Perceived time to travel to Andromeda Galaxy is 2537000.0 years

Test Cases

These test cases will be used to test your program when the TAs are grading. It's only wise to make sure that your program runs these successfully. The example runs above also are used as test cases.
Description of CaseInputsExpected Output/Behavior
3. Normal Velocity near low end of range 1.0
        Weight of the shuttle is 70003.50026252188 kg
        Perceived time to travel to Alpha Centauri is 4.366782 years
        Perceived time to travel to Barnard's Star is 5.9997 years
        Perceived time to travel to Betelgeuse is 642.467874 years
        Perceived time to travel to Andromeda Galaxy is 2536873.146829 years
4. Normal Velocity near high end of range 99.0
        Weight of the shuttle is 496216.8435058348 kg
        Perceived time to travel to Alpha Centauri is 0.616041 years
        Perceived time to travel to Barnard's Star is 0.846404 years
        Perceived time to travel to Betelgeuse is 90.635779 years
        Perceived time to travel to Andromeda Galaxy is 357887.891804 years
5. Special case, Velocity zero 0
        Weight of the shuttle is 70000.0 kg
        Perceived time to travel to Alpha Centauri is 4.367 years
        Perceived time to travel to Barnard's Star is 6.0 years
        Perceived time to travel to Betelgeuse is 642.5 years
        Perceived time to travel to Andromeda Galaxy is 2537000.0 years
6. Invalid input, Velocity smaller than zero% -5 Velocity is too small, using 0.01% instead
        Weight of the shuttle is 70000.00035000002 kg
        Perceived time to travel to Alpha Centauri is 4.367 years
        Perceived time to travel to Barnard's Star is 6.0 years
        Perceived time to travel to Betelgeuse is 642.499997 years
        Perceived time to travel to Andromeda Galaxy is 2536999.987315 years
7. Invalid input, Velocity exactly 100% 100 Velocity is too large, using 99% instead
        Weight of the shuttle is 496216.8435058348 kg
        Perceived time to travel to Alpha Centauri is 0.616041 years
        Perceived time to travel to Barnard's Star is 0.846404 years
        Perceived time to travel to Betelgeuse is 90.635779 years
        Perceived time to travel to Andromeda Galaxy is 357887.891804 years
8. Invalid input, Velocity greater than 100% 115 Velocity is too large, using 99% instead,
        Weight of the shuttle is 496216.8435058348 kg
        Perceived time to travel to Alpha Centauri is 0.616041 years
        Perceived time to travel to Barnard's Star is 0.846404 years
        Perceived time to travel to Betelgeuse is 90.635779 years
        Perceived time to travel to Andromeda Galaxy is 357887.891804 years
9. Invalid input, Non-numeric input ABC Program crashes

Note on the Special Case, yes, if you traveled at 0 miles per hour, you'd never get there. But it is a fact that zero as a velocity does work in the equation. Sometimes results are not realistic!

Note on the Invalid input case, velocity smaller than zero - the numbers are actually generated with 0.01% instead of 0.1%. Sorry about that! If you're already submitted the program, don't worry about it. If you are still writing, please make the change to 0.01. Thanks!

Design:

Write the design for the program in pseudocode. The design is started for you. You need to put this design in a file called design1.py.

# supply program prolog  
#   name, email, purpose, pre-conditions, post-conditions, references
    # Display introductory message 
    # Ask user for velocity as a percent of speed of light
    # Display a message about the velocity

    # if velocity is 100 percent or more
    #        (some of your design here)

    # elif velocity is negative
    #        (some more of your design here)

    # (some more of your design here)

    # convert input to percent by dividing by 100
    # calculate the time dilation factor
    # calculate the weight of the spaceship, multiplying by factor
    #      starting weight 70000.0 kg

    # (some more of your design here)

    # display results of four stars

Fill in the missing steps in the design. You should design the program so that if the user gives invalid numeric inputs the program handles it. See the test cases above. The program does not have to handle non-numeric inputs.

Submit this design1.py file with the link above on or before Wednesday, September 27, midnight. Use the menu choices of "Design" and "Program 1".

Implement the design

Individually write a Python program to implement your design. You can use the assistant of tutors, any TA, your instructor, the Net, and one student from CS 115 who is not working (nor has been working) with any other student. Any of these resources that you use must be referenced in your program header. Start with a copy of the Python file you have that has the design in it (design1.py) and 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 are important! Verify that it does come out with the correct answers.

Name your program file lightspeed.py and submit it on or before Sunday, October 8, midnight. Use the submit link at the top of the page, use the menu choices of "Code" and "Program 1".

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

Please read the documentation standard on the class web page. As you can see from looking at the grading page, we will be looking to see how you meet these standards. Note particularly that we require a header comment!

Make sure you read the FAQ page at the top of the assignment. Those are requirements!