Honors 270 Assignment 1

Due September 8

Directions

  1. Running Programs in Python

    This problem involves loading running the example program "convert". First, compile the convert.py. To do this first save a copy of the Python file to your account - you probably want to a have a directory (folder) for this course.

    To run this program, open up a terminal window and change to the directory holding that file. Make the file executable bby typing the followin command into the terminal window:

      chmod a+x convert.py
    

    Then to run it, type: python convert.py

    Now run convert with the following inputs for the number of seconds: 0, 100, 100.111, 9347, 555554, -11, and 12345678901 . Copy and paste all of your results into your solution for this assignment.

    1. Discuss the results for 100.111, and 12345678901 .
    2. Now change
      total = input("Please enter a time in seconds ")
         
      to
      total = int(input("Please enter a time in seconds "))
         
      and then rerun the program with 100.111. What happens? Why?
  2. Alter the program above

  3. Being able to take someone else's code and make alterations to it (even when you don't know the language in question) is an important skill to have. Now you will alter the "convert" program that you used above to calculate the number of days, hours, minutes, and seconds instead of just the number of hours, minutes, and seconds. Test your new code with the input listed above. Copy and paste your results into your homework solution.

    1. How do the results compare to the results that you had above?

  4. One more alteration

  5. Now create a third version of convert. Change the input line to:

    total = float( input("Please enter a time in seconds "))
    
    in your code. This will make total be a loating point (decimal) number. You will also need to the function int() around all of your calculations to force the results to be integers. So if you had
     
    hour = total / 3600
    
    it should become
    hour = int(total / 3600)
    
    Test your program with the input above and with 1234567890123456789. Copy and paste your results into your homework solution.

    1. What has changed? Do you results now match what you expect?