CS414 Fall 2017: Assignment #1

Due Thursday, February 9, 2017, before midnight

Late penalty: Fri 5%, Sat 10%, Sun 100%

Before You Begin:

Questions:

  1. Loops and float-to-int conversion:

    Write a program temp_table.py that prints a temperature conversion table. It should look something like this:

            Celsius Fahrenheit
            -40 -40
            -35 -31
            ...
            35 95
            40 104
          
    The Celsius temperatures should range from -40 to +40 (inclusive), in steps of 5 degrees.

    The Fahrenheit temperatures should be rounded to the nearest integer.

  2. Geometry:

    Write a program sphere.py that prompts the user for the radius of a sphere (a float), and prints the sphere's circumference, surface area, and volume.

    In case you forgot all the geometry you learned in high school, here are the formulas:
    Circumference = 2πr
    Area = 4πr2
    Volume = (4/3)πr3

    Some gotchas to be aware of:

  3. Booleans:

    Write a program monotonic.py that gets three ints x, y, and z from the user, checks if they form a monotonic sequence, and prints either monotonic or non-monotonic. This means they for an increasing sequence, or a decreasing sequence:
    x ≤ y ≤ z or
    x ≥ y ≥ z.
    Examples:

            x is 1, y is 2, z is 3: is a monotonic sequence
            x is 1, y is 1, z is 3: is a monotonic sequence
            x is 2, y is 1, z is 3: is a non-monotonic sequence
            x is 3, y is 2, z is 1: is a monotonic sequence
          
    Gotcha: You can't type x <= y <= z. That's a syntax error.

  4. Payroll:

    Write a program payroll.py that prompts the user for two numbers relating to an employee's work week: the hours worked, and the hourly pay rate.

    It then computes the employee's gross pay, and prints it. Any hours worked beyond 40 are paid as overtime, at a rate 1.5 times the usual hourly rate ('time and a half').

  5. (Bonus 10%):

    Consider this rule for transforming a positive integer n:

    The Collatz conjecture says that, no matter what integer you start with, applying this transformation over and over will eventually reach the value 1.

    Write a program collatz.py that prompts the user for a starting value n, applies the above transformation repeatedly, until n is 1. The program should simply count the number of transformations it took to reach 1, and print that count.

    Examples:

Turn in your work

To turn you work in, go to mycourses.unh.edu, find CS414 and assignment 1, click the "Submit" button, and upload temp_table.py, sphere.py, monotonic.py, payroll.py, and maybe collatz.py .