ENGG1003 Lab09 PythonDataProcessing
ENGG1003 Lab09 PythonDataProcessing
I declare that the lab work here submitted is original except for source material explicitly
acknowledged, and that the same or closely related material has not been previously submitted
for another course.
I also acknowledge that I am aware of University policy and regulations on honesty in academic
work, and of the disciplinary guidelines and procedures applicable to breaches of such policy
and regulations, as contained in the website.
That means,
totalWage = number of dollars paid per hour x
total number of hours worked by an employee in a week
in the supermarket.
Python function recap
A python function works in a following way:
Anything that starts with # is a comment which is not executed
parameters
Pass the
to calculate weekly wage.
The function shall return a
value as result.
#code to call the function
- Request parameters Complete the code
After completing the function, to call the function
- Call the function
add some code to call the
calcWeeklyWage() function.
Print and check the result
Locate a given comment line
# Call the function for TASK 1
Task 1
To start, download the “employeeWage.py” file from Blackboard.
Add some code to get some user input, test and check the result
We shall use input("...") statement to ask for total hours of work that is a float
type value.
return total_Weekly_Wage
# Output
print(f'Wages for {totalHours} hours at ${hourlyWage} per hour
are ${total_Weekly_Wage}')
Task 1 – Check your output
Inputs Outputs
hourlyWage FIXED in TASK 1 totalHours total_Weekly_Wage
(will change in TASKS 3 and 4) calcWeeklyWage( )
55 40 $2200.0
55 30 $1650.0
55 28.5 $1567.5
Completion Reminder:
After completing task 1, save your work in “employeeWage.py”
Make sure the “employeeWage.py” file has complete code of task 1.
Task 2
Task 2 Scenario
Let us now assume that every employee of CUHK supermarket
work for 40 hours/week as a standard.
Employees can also work overtime (OT), i.e., beyond 40 hours, the
hourly wage of extra hour(s) will increase by 50%, i.e., as 1.5
times.
For example: an employee worked for 42.8 hours a week and the
employee is paid $55 per hour (same FIXED rate as in TASK 1)
parameters
Pass the
calcWithOverTimeWage( ) :
if an employee worked for 40
hours or less, calculate the Define the function
calcWithOverTimeWage( first, then make use of
weekly wage by calling task 1 calcWeeklyWage()
)
function calcWeeklyWage( ) function in operation
parameters
Pass the
Calculate OT paid by calling
calcWeeklyWage( ) again.
#code to call the function
Complete the code
Remember to include the - Request parameters
- Call the function to call the function
standard paid for the first 40
hours of work!
Print and check the result
The function shall return a
value as result.
Task 2 Scenario
# Assume
hourlyWage = 55
# Input
totalHours = # Keep the statement you have created in task 1
# Process
# KEEP Your function call for TASK 1
# Call the function for TASK 2.
Type here to call the calcWithOverTimeWage( ___ , ___ )
total_Weekly_Wage = function
# Output
print(f'Wages for {totalHours} hours at ${hourlyWage} per hour are
${total_Weekly_Wage}')
Task 2 – Check your output
Inputs Outputs
hourlyWage FIXED in TASKS 1 and 2 totalHours total_Weekly_Wage
(will change in TASKS 3 and 4) calcWithOverTimeWage()
55 39.5 $2172.5
55 50 $3025.0
55 45 $2612.5
Completion Reminder:
After completing task 2, save your work in “employeeWage.py”
Make sure the “employeeWage.py” file contains complete
code for task 2 calcWithOverTimeWage( ) and
code for task 1 calcWeeklyWage( ).
Task 3
Task 3 Scenario
Let us now assume now, that there are three pay scales in
CUHK supermarket.
Their total number of working hours in a week and the scale
point list are given in the table.
parameter
Call calcWeeklyWage()
Pass the
from task1
s
In task 3, the idea is to use the pay
scale to determine weekly wage of
an employee. calcWithOverTimeWage()
parameter
Pass the
Call calcWithOverTimeWage()
hours worked (as in Tasks 1 and 2)
s
from task2
parameters
Pass the
Finally, by using hourly wage
information and hours worked,
calculate the weekly wage.
#code to call the function
- Request parameters Complete the code
Reminder: take into account OT too! to call the function
- Call the function
42 1 $2365.0
45 2 $3325.0
35 3 $2800.0
Submission Details:
After completing task 3, save your work and submit the completed
“employeeWage.py” file on Blackboard
Please note: Make sure the completed “employeeWage.py” file has
complete codes of tasks 1, 2 and 3.
Bonus Task 4
Task 4 Scenario
In this task we introduce 4 employee roles with various pay scale.
You are required to map the employee role to the pay scale, thus hourly
wage.
Pay scale and hourly wage information are shown in the table below:
CUHK Supermarket Scale Point List (Same as TASK 3)
Employee role Pay scale Pay Scale Hourly Wage
manager 3
3 80
supervisor 2
accountant 1 2 70
worker 1 1 55
Observe that "accountant" and "worker" have the same pay scale.
That means same pay scale can be assigned to more than one
employee roles.
OT and all previous wage calculations shall be taken into account.
Bonus Task 4 Scenario
If you attempt Bonus Task 4, you shall surrender part of your work in Task 3!!
Your program asks the user for these inputs:
number of hours worked in a week, keep the same line as in Tasks 1, 2 and 3
COMMENT to DISABLE payScale input statement line in Task 3
employee role that is a text input (str) containing a mixed-case word
Create a new function named roleWage( ) that takes two arguments,
totalHours and employeeRole.
Argument employeeRole is expected to be a single word in lower-case:
manager or supervisor or accountant or worker
This function determines a payScale from employeeRole using if-elif-else;
set payScale to -1 if employeeRole is not matched
This function calls scaleWage() function to obtain and return end results
Ø During Input and Testing, we shall convert the user input to lower-case
Ø E.g., name = "PeTer".lower() name will be "peter"
Ø E.g., "MaNagEr" "manager", by using the .lower() str function
Bonus Task 4 FOLLOWS Task 3
Step 3 Step 2
Step 6 Step 7
parameters
Return result
parameters
Pass the
Pass the
Step 5
Step 4
Step 1
Inputs Outputs
totalHours employeeRole total_Weekly_Wage
37 manager $2960.0
41 supervisor $2905.0
45 accountant $2612.5
45 worker $2612.5
Bonus Task 4 - Submission