Due Thursday, February 9, 2017, before midnight
Late penalty: Fri 5%, Sat 10%, Sun 100%
cs.unh.edu/~cs414
.
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 104The Celsius temperatures should range from -40 to +40 (inclusive), in steps of 5 degrees.
The Fahrenheit temperatures should be rounded to the nearest integer.
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:
4 / 3 == 1
because python 2.7 does integer division. Use
floats instead.
a b
is an error.
Write a program
monotonic.py
that gets
three int
s 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 sequenceGotcha: You can't type
x <= y <= z
. That's a
syntax error.
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').
Consider this rule for transforming a positive
integer n
:
n
is even, divide it by 2The 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:
n
== 1: 0 transformationsn
== 7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 ->
13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1: 16
transformations.
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
.