Use of procedures, parameter passing, block structures, data types, arrays, abstract data structures, conditional control, iterative and recursive processes, and input/output in programming solutions to a variety of problems. Prerequisite: None.

Lab 3 - Introduction to Functions - (50 points)



Due date: 3/1/2019 at 11:59pm

Objectives



  • Practice with functions
  • Learn about function parameters

Part 1 - Payroll management using functions (25 points)



Write a Python program (payroll.py) that does the following:

  • Print a message that says "Welcome to the Payroll Manager!"
  • Define a function (payroll_calculator) that has the following three parameters: employee name, hours worked that week, and pay rate in dollars per hour.
  • In the payroll_calculator, calculate the employee's salary as the number of hours worked multiplied by the rate. If the employee has worked more than 40 hours, then calculate overtime as 1.5 times the regular pay rate and add that to the salary. When the total salary has been calculated, print the name, hours worked and the salary in one line.

  • Define the main function that contains five calls to the payroll_calculator function with various names, hours worked, and pay rates. Make sure to call the main() function in your program.
  • Make sure to test your program such that it works with different pay rates and hours worked. Note. This program has NO user input.

Part 2 - Rock Paper Scissors game (25 points)



Write a Python program (rockpaperscissors.py) that does the following:

  • Import the random module into your program
  • Write a function called computerRPS() that uses the random number generator to return one of "rock", "paper", or "scissors"
  • In the main() function, print a welcome message to the user
  • Ask the user for their choice - rock/paper/scissors. Perform input validation and only accept valid input.
  • Call the computeRPS() function and save the returned "computer's choice" value in a variable
  • Display the user's choice and the computer's choice.
  • Now as per the rules of the game, display whether the player or the computer is the winner.
  • The rules are as follows:

    1. If both the computer and the player pick the same (rock/paper/scissors), it is a tie.
    2. Rock beats scissors.
    3. Paper beats rock
    4. Scissors beat paper
  • Based on the rules mentioned above, determine whether it is a tie, or whether the computer won or whether the player won and display a message accordingly.
  • Ask the user if s/he wants to play again and go back to the beginning if the user enters a 'y' or 'Y'. Perform input validation for the yes/no option.

Submitting the lab using submit directory



Make a folder for lab3 in your labs folder and turn in the following on Canvas:

  • payroll.py
  • rockpaperscissors.py
  • README file