02 Team Activity: Calling Functions

Instructions

Each lesson in CSE 111 contains a team activity that is designed to take about one hour to complete. You should prepare for all team activities by completing the preparation material and the individual checkpoint assignment before starting a team activity. The goal of the team activities is for students to work together and teach and learn from each other. As your team completes a team activity, instead of moving through it as quickly as you can, you should help everyone understand the concepts.

Face-to-Face Students

Face-to-face students will complete the team activities in their classroom during class time.

Online Students in a Semester Section

Online students in a semester section will arrange and participate in a one hour synchronous video meeting with your team for each team activity. As your team works through the assignment, be certain that each student can see the code that is being typed. When your team completes the video meeting, share the final Python file with everyone on your team.

Online Students in a Block Section

Students in a block section complete two lessons each week. This means that online students in a block section will complete two team activities each week. For one of these two activities, your team should arrange and participate in a one hour synchronous video meeting. For the other team activity, your team may meet in a synchronous video meeting or your team may collaborate, ask and answer questions, and share code in Microsoft Teams.

As your team works through a team assignment in a synchronous video meeting, be certain that each student can see the code that is being typed. When your team completes the video meeting, share the final Python file with everyone on your team.

Purpose

Improve your understanding of calling built-in Python functions and calling functions and methods that are in a standard Python module.

Problem Statement

You work for a retail store that wants to increase sales on Tuesday and Wednesday, which are the store’s slowest sales days. On Tuesday and Wednesday, if a customer’s subtotal is $50 or greater, the store will discount the customer’s subtotal by 10%.

Assignment

Work as a team to write a Python program named discount.py that gets a customer’s subtotal as input and gets the current day of the week from your computer’s operating system. Your program must not ask the user to enter the day of the week. Instead, it must get the day of the week from your computer’s operating system.

If the subtotal is $50 or greater and today is Tuesday or Wednesday, your program must subtract 10% from the subtotal. Your program must then compute the total amount due by adding sales tax of 6% to the subtotal. Your program must print the discount amount if applicable, the sales tax amount, and the total amount due.

Core Requirements

  1. Your program asks the user for the subtotal but does not ask the user for the day of the week. Your program gets the day of the week from your computer’s operating system.
  2. Your program correctly computes and prints the discount amount if applicable.
  3. Your program correctly computes and prints the sales tax amount and the total amount due.

Stretch Challenges

If your team finishes the core requirements in less than an hour, complete one or more of these stretch challenges. Note that the stretch challenges are optional.

  1. Add code to your program that the computer will execute if today is Tuesday or Wednesday and the customer is not purchasing enough to receive the discount. This added code should compute and print the difference between $50 and the subtotal which is the additional amount the customer would need to purchase in order to receive the discount.
  2. Near the beginning of your program replace the code that asks the user for the subtotal with a loop that repeatedly asks the user for a price and a quantity and computes the subtotal. This loop should repeat until the user enters "0" for the price.

Helpful Documentation

Testing Procedure

Verify that your program works correctly by following each step in this testing procedure:

  1. If today is any day except Tuesday or Wednesday, run your program using the inputs shown below. Ensure that your program’s output matches the output shown below.
    > python discount.py
    Please enter the subtotal: 42.75
    Sales tax amount: 2.56
    Total: 45.31
    
    > python discount.py
    Please enter the subtotal: 55.20
    Sales tax amount: 3.31
    Total: 58.51
  2. If today is Tuesday or Wednesday, run your program using the input shown below. Ensure that your program’s output matches output shown below.
    > python discount.py
    Please enter the subtotal: 42.75
    Sales tax amount: 2.56
    Total: 45.31
    
    > python discount.py
    Please enter the subtotal: 55.20
    Discount amount: 5.52
    Sales tax amount: 2.98
    Total: 52.66
  3. Is there a simple way to test your program for all the days of the week without testing on seven consecutive days and without changing your computer’s operating system date? Hint: In your program immediately after these three lines of code:
    # Call the weekday() method to get the day of the
    # week from the current_date_and_time object.
    day_of_week = current_date_and_time.weekday()
    
    temporarily add a line of code like this one:
    day_of_week = 2
    

Sample Solution

Please work diligently with your team for the one hour meeting. After the meeting is over, please compare your program to the sample solution or the stretch solution. Please do not look at the sample solutions until you have either finished the program or diligently worked for at least one hour. At the end of the hour, if you are still struggling to complete the assignment, you may use the sample solution to help you finish.

Ponder

During this assignment, you wrote code that calls the datetime.now() and datetime.weekday() methods. What did these two methods do in your program? If these two methods didn’t exist, would this assignment have been more difficult to complete?

Submission

When you have finished the activity, please report your progress via the associated I‑Learn quiz. When asked about which of the requirements you completed, feel free to include any work done during the team meeting or after the meeting, including work done with the help of the sample solution, if necessary. In short, report what you were able to accomplish, regardless of when you completed it or if you needed help from the sample solution.