Demonstrate the Kinds of Error We Get When Typing in Python Code

Total Page:16

File Type:pdf, Size:1020Kb

Demonstrate the Kinds of Error We Get When Typing in Python Code

ISTA 130 Lab 2: 12-Sep-2011 1) Section Leader Recitation  Demonstrate the kinds of error we get when typing in Python code  Discuss more complex conditions with and or not

2) Lab Activity In Teams of two, complete the following three programs 1. We highly encourage you to work with a lab partner. Working with a partner requires the ability to proceed at a pace where both partners understand what is going on. This is a great way to learn. You are helping each other learn. Please do not have one partner rip out the code while the other partner is not involved, not understanding, and not prepared to complete upcoming programming projects. If you feel it is more appropriate for your personality and skill level, you may work on your own.

Program 1 At many companies, an employee’s weekly gross pay is based on their hours worked and hourly rate of pay for that week. Any hours worked over 40 in a week are considered overtime and are calculated at 1.5 times the hourly rate. Write a Python program named grossPay.py that gets the hours worked (a float like 30.5) and the hourly rate of pay (a float like 7.75) and computes the gross pay with overtime consideration. Test your program with several sets of inputs. Assume the inputs will always be valid numbers and >= 0.0. Your dialog should look like these: Enter hours worked: 38.0 Enter hours worked: 40.0 Enter hours worked: 42.0 Enter hourly rate: 10.00 Enter hourly rate: 10.00 Enter hourly rate: 10.00 Pay = 380.0 Pay = 400.0 Pay = 430.0

Program 2 The body mass index (BMI) is calculated as a person’s weight (in pounds) times 720, divided by the square of the person’s height (in inches). A BMI in the range 19-25, inclusive, is considered healthy. Write a Python program named bodyMassIndex.py that gets the user’s weight (in pounds) and their height (in inches) and computes their BMI, prints the value and a message indicating whether they are above, within, or below the healthy range. Assume both inputs > 0. Your dialog should look like these:

Weight in pounds? 120 Weight in pounds? 142 Weight in pounds? 222 Height in inches? 70 Height in inches? 67 Height in inches? 73 17.6 BMI is below range 22.8 BMI is within range 30.0 BMI is above range

Program 3 Given four String inputs, compute the String that is not "greater than" the other three. This is the string that alphabetically precedes the other three (or it may be equal to one or more of those other three strings that also precede the others alphabetically). Write a Python program named firstString.py that computes which of the four inputs precedes the others. Your dialog should look like these: String 1: d String 1: Kim String 1: Kim String 1: bbbb String 2: b String 2: Li String 2: chris String 2: ccc String 3: a String 3: Chris String 3: lowerCase String 3: bbb String 4: c String 4: Devon String 4: Kim String 4: cccc First: a First: Chris First: Kim First: bbb

1 Note: Working in Monday labs with another student is highly encouraged. However when working on ISTA 130 Programming Projects, you are required to work alone with help only from our textbook, our lectures, sample programs from this course, Rick, and section leaders. Copying another person's Programming Project in any manner or having another person writing any part of a Programming Project would be a violation of the code of academic integrity. This includes looking at code from another screen.

Recommended publications