CS2 Python Project 2024 🎰

<<< Back to main site

Due Date: Tuesday, December 3, 2024
This is your final project of CS2!

Need help? Remember to check out Edstem and our Website for TA help assistance.

Background 🎰

Be sure to read all background notes, as they are vital to do the assignment.

Assignment Goals

Resources


Project Description 🎰

Problem Introduction

The entire Brown student body decides to go to Providence's very own Don's Casino. Don, the owner, becomes overwhelmed and asks for your assistance. He needs help calculating chip exchanges and managing bets at the various game tables.

Detailed Requirements

You will be writing functions to perform the following tasks:

We have provided two lists to get you started: chip_values and cash_denominations. Continue reading for more guidance on how to use these lists in your functions!

Tasks 🎰

Task 1 Double click your CS2 folder on your desktop, and enter your folder for Python. Then, create a new folder inside called Python Project. All your files for the project should live in this folder.

Task 2 Download the stencil file for this project, and put it in your Python Project folder you just created!

Task 3 Open up your Python Project folder by dragging the folder into Visual Studio Code, or by opening up Visual Studio Code, clicking Open under the Start header, and finding the folder in your file system.

Once the folder has opened, you should see our stencil file, stencil.py on the lefthand side of the screen. Double click the file, and you should see that it already contains some lines of code. Now we'll learn what this code represents!

Documentation

In your Python Project stencil, you will find two lists. Recall from Lab 6 that in Python you can make lists to group things together. We have provided you with two lists: chip_number and cash_exchanged.

chip_number: assume that Don's Casino has four players. This list contains the number of chips that each player wants to exchange their cash for. They request the following chip denominations:

cash_exchanged: this list contains the amount of cash that each player exchanged for chips. Assume that they provide the following amounts of cash:

Task 4 Populate (fill) both the chip_number and cash_exchanged lists with the values from above for the four players.
Remember that order matters in a list. We want to ensure that player 1 is in the first "slot", or index 0, and that player 4 is in the fourth "slot", or index 3.

Hint

These lists should contain integer values only, as we will be performing calculations with their values!
For example, the first number in chip_number should be 25, and the first number in cash_exchanged should be 70.

Note that we have also given you the variable exchange_fee, which is equal to 1.02 (2%). Remember to account for the exchange fee when you are calculating the total chips a player receives!

Function 1: Calculate Change

Task 5 You want to buy 25-dollar chips. Define a function, called calculate_change, that takes in the number of 25-dollar chips in an order and the amount paid, in cash, by the customer.

Recall from lab that defining a function means writing the first line as follows:

def function_name(parameter1, parameter2, ...):
Hint

Recall what we learned in Python Lab II about parameters, or inputs, for a function. How can we use these parameters to perform calculations? How many parameters does this function need?

Task 6 For this function, the total cost of a purchase will be the number of chips multiplied by $25.00 per chip, multiplied by our exchange fee rate of 1.02.

Write a calculation within your calculate_change function that computes the amount of change to be returned to a customer. To do so, you will need to determine the difference between the amount paid, in cash, and the total cost of their order.

To ensure that our function returns a valid amount of change, we will use Python's round function to round the change to 2 decimal places. You can read more about round here: W3 Schools.

Make sure to then return that value at the end of the function!

Function 2: Take Order

Don's next task for you is to take a customer's request. To take a request, you will need to take in the customer's desired number of 25-dollar chips and the amount paid, in cash. To complete the order, we have to ensure that they paid enough! This will involve calling our previous function.

Task 7 Define a function, called take_request, that takes in the number of 25-dollar chips the player wants and the amount paid, in cash, by the player.

Task 8 Begin by considering if the player has paid enough to complete their order. In the first line of the function, determine the amount of change for their order using your calculate_change function.

The order is almost completed! However, there may be a couple of conditions that we want to consider before returning a completion message to the customer.

Task 9 Stop and consider what condition may prevent us from fulfilling an order.

Answer
  • The first condition should check that the customer has paid us enough! We don't want to proceed if we don't have enough money. If the change that we calculated is less than $0, we didn't receive enough money.
  • Given that the customer's payment was sufficient, we now want to complete their order!

Task 10 In your conditionals, print the following messages according to the validity of the order:

  1. "I'm sorry! You don't have enough money for your <CHIP NUMBERS HERE> chip(s)."
  2. "Thank you for coming to Don's Casino! Your change is $<CHANGE HERE>"

Final Task

Now that you've implemented the two required functions for Don's Casino, we want to quickly take all four customer's requests. We can do this using a for-loop,
as we learned about in Lab 6!

Task 11 Loop through the range of the length of chip_number. This means we want to go through each item in the list one by one. The range() function in Python helps with that. It generates a sequence of numbers from 0 up to (but not including) the specified number. In our case, it generates numbers from 0 to 3 (because the length of the list is 4).

Within our loop, we want to do the following:

  1. Determine the number of chips for the customer at the current index (Hint: use chip_number).
  2. Similarly, determine the cash given at the current index (Hint: use cash_exchanged).
  3. Take the customer's order (by calling the take_order function) based on the current number of chips and the corresponding amount of cash given in each run of the loop.

Extra Credit

3 points: End of Day Summary!

Don would love to know the number of 25-dollar chips that were exchanged today, and how much cash "went through" his register. After your for loop has finished running, print the total number of chips for the day and the total amount of cash given by customers in the day.

Hint

There are ways you can easily add up everything in a list! Trying checking out the Python sum function online!

6 points: Write an algorithm to compute actual change denominations!

Don needs you to perform the role of a cash register! If the person has given you enough money (if the change > 0), and you print out the person's change, Don then wants you to be able to print out the exact denominations of that change afterwards.

For example, if the change is $8.58, Don wants to see:

1 $5 dollar bill(s)
3 $1 dollar bill(s)
2 quarter(s).
1 nickel(s).
3 pennies.

Write an additional function called calculate_denominations that takes in an amount of change, and call it in that branch of the if statement. calculate_change should print the number of 10s, 5s, 1s, quarters, dimes, nickels, and pennies that make up the change the customer deserves!

Note: This is a VERY difficult extra credit!


Hand-In 🎰

To Hand-In Project 5:
Go to Canvas and go to the Project 5: Python assignment. When you submit, be sure to include your stencil.py file.

  1. Make sure your source file does not contain your name. This is especially important in order to maintain the course’s anonymous grading policy that ensures your assignments are graded fairly. We will deduct points if your files contain identification data.

  2. Make sure you have the correct, most up-to-date file before zipping. We’ve had students in the past send in older versions that didn’t contain all their finished work! You will receive a 10% deduction if TAs must regrade your work due to incorrect files.

  3. Create a .zip file from your Python Project folder.

    Windows:

    In Windows Explorer, go to the folder containing the files you want to zip. Select the files, then right-click on any of the selected files and select Send To… -> Compressed (zipped) Folder.

    Mac:

    In Mac Finder, go to the folder containing the files you want to zip. (This would be your “JavaScript Project” folder) Select the files, then right-click on any of the selected files and select Compress Items.

  4. Right click on the newly created zip file to rename it. The name of your file should be BannerID_PythonProject.zip (replace "BannerID" with your own banner id, starting with B0...)

  5. Submit on Canvas under the Python Project assignment!

Congrats! You just finished your final CS2 project! 🎰

If you have any issues with completing this assignment, please reach out to the course HTAs: cs0020headtas@lists.brown.edu

If you need to request an extension, contact Professor Stanford directly: don.stanford@gmail.com