Lab 9  Decisions

Lab Index  Course Home Page

Task 1:  Pay with Overtime

Complete the program below, so it calculates and displays weekly pay with overtime.  The part provided gives you the hourlyRate (when not on overtime) and the total number of hours.  Use the usual rule that the person is pay time and a half (1.5 times the normal rate) for hours over 40.

For example if someone is paid $9.50 per hour,  the pay for 30 hours would be 30*9.50.  The pay for 45 hours would be 40*9.50 + (45-40)*1.5*9.50.

#weekly pay

hourlyRate = input("Enter your pay rate in dollars per hour: ")
hours =  input("Enter your number of hours for the week: ")

# calculate the value of a variable called pay here 

print "Your weekly pay is $%0.2f." % pay

Task 2:  Pay with Overtime and Double Time

Make a modification of Task 1 that assumes the person is paid double time for hours over 60.  Extending the example above, the pay for 70 hours would be
40*9.50 + 20*1.5*9.50 + (70-60)*2.0*9.50.

Task 3:  Horizontal and vertical lines

Download polygon4.py.  In free-form drawing programs, it is hard to draw an exactly horizontal or vertical line when you want one, since it is hard to exactly match coordinates for the tiny pixels.  Some programs have a mode where if you select a point that would make an almost horizontal or almost vertical line, the program shifts your selection to make it really horizontal or vertical.  At present polygon4.py does not make any changes to your mouse clicks, but it is set up for you to make small changes so it will be able to alter some points added to the polygon vertices.  It creates variables for the x an y coordinates of the most recent mouse click.  It also sets variables prevX and prevY for the x and y coordinates of the previous vertex.  This version does not really use those lines of code:  it just sets the Point revisedPt to have the same coordinates as the latest mouse click. 

You are to make the small changes in the location indicated in the code to change the x and y coordinates to match the previous one if they are "close enough" to the previous one.  Set closeEnough = 10.  The easiest way to get the unsigned distance between two values is the abs function, that converts negative values to positive:  abs(5) is 5; abs(-15) is 15.  For instance if the previous x coordinate was 75, and the most recent x coordinate clicked is 80, abs(80 - 75) is 5, which is no bigger than the closeEnough value 10, so x should be changed to 75, matching the previous value.   On the other hand if the previous y coordinate was 40 and the most recent is 25, abs(25 - 40) is 15 which is larger than the closeEnough value 10, so you would not do anything to change the y coordinate 25.  

Show a TA your work on Task 2 and 3.

Lab Index  Course Home Page