CS代考 Python Exam: Expense Management System

Python Exam: Expense Management System
You must submit the completed program as per instructions provided on Canvas and in Codio. You CANNOT:
● Work with someone else on this exam.
● Copy from someone else’s exam.

Copyright By PowCoder代写 加微信 powcoder

● Use StackOverflow.
● Use an internet search for keywords in the exam. For example, do not Google “loading a
.csv file in Python”.
● Discuss the exam with other students until cleared by the instructor to do so. Other
students have not yet taken the exam, and you CANNOT provide academically dishonest assistance to them.
● Reference any material from the course or recitation. This includes videos, slides, code samples, homework assignments, quizzes, and coding exercises.
● Reference any online Python documentation.
Use of Ed Discussion/Office Hours as it Relates to the Exam
● You CAN ask any question on Ed Discussion or during office hours that directly relates to the exam logistics and/or technical errors with Codio or Canvas. For example, you can ask about a glitch in Codio unrelated to your code.
● You CANNOT ask a question specifically related to code or “how to do something”. For example, you cannot ask “How should I go about writing the code for this function?”. You also cannot post code and ask “Can you help me understand why my code isn’t working?”
The Assignment
This Python exam will involve implementing a system for managing expenses. You will download the skeleton of the program, then implement the functions. The design of the program has been set up for you.
Introduction to Software Development

Introduction to Software Development
In this system, users will be able to add and deduct expenses, update expenses, sort expenses, and export filtered expenses to a file. The program will initially load a collection of expenses from 2 different .txt files (in the same format) and store them in a dictionary.
Steps for Completing the Exam
1. Complete all of the required functions
a. Implement all of the functions defined in expenses.py
b. Docstrings have already been provided
c. Add comments to your code
d. You can create any number of helper functions (with docstrings).
e. The main function has already been implemented for you. DO NOT CHANGE THE
CODE IN MAIN.
2. Test your code by running (and passing) all of the provided test cases in the given
expenses_test.py.
a. Write additional test cases as noted and make sure they pass as expected. Your
test cases should be distinct.
3. Make sure your entire program and the unit testing file run without errors!
Required Functions
Below you will find explanations of the functions that need to be written in the program (expenses.py). We are expecting to see these functions with these names and signatures exactly. Do not change the names of these functions as we will be running automated tests against each individual function. You will fail the autograded tests if you change the function names or signatures. You will also fail each test unless you remove the raise NotImplementedError line in each function.
Be sure to add comments to your code.
def import_expenses(expenses, file):
● Reads data from the given file and stores the expenses in the given expenses dictionary, where the expense type is the key and the total expense amount for that expense is the value.
● The same expense type may appear multiple times in the given file.
● Ignores expenses with missing amounts. If a line contains both an expense type and an
expense amount, they will be separated by a colon (:).

Introduction to Software Development
● You can assume that if they exist, expense types are one-word strings and the amounts are numerical.
● Strip any whitespace before or after the expense types and amounts.
● Blank lines should be ignored.
● Expenses are case sensitive. “coffee” is a different expense from “Coffee”
● Note: This function will be called twice in main with the same dictionary but different
● This function doesn’t return anything. Rather, it updates the given expenses dictionary
based on the expenses in the given file.
def get_expense(expenses, expense_type):
● Prints and returns the value for the given expense type in the given expenses dictionary.
● Prints a friendly message and returns None if the expense type doesn’t exist. (Note:
Printing a friendly message means that the program should not raise an error or otherwise terminate. Simply tell the user that the requested expense type does not exist and continue the program. Also note that None is a specific keyword in Python of NoneType. You should not return a string “None” from this function.)
def add_expense(expenses, expense_type, value):
● Adds the given expense type and value to the given expenses dictionary.
● If the expense type already exists, add the value to the total amount.
● Otherwise, creates a new expense type with the value.
● Prints the updated expense amount.
● This function doesn’t return anything.
def deduct_expense(expenses, expense_type, value):
● Deducts the given value from the given expense type in the given expenses dictionary.
● Raises a RuntimeError if the value is greater than the existing total of the expense
type. Note: You are not supposed to use try/except to catch the RuntimeError you raised. We expect the function to raise a RuntimeError if the value is greater than the existing total of the expense type.
● Prints a friendly message if the expense type doesn’t exist. (Note: Printing a friendly message means that the program should not raise an error or otherwise terminate. Simply tell the user that the requested expense type does not exist and continue the program.)
● Print the updated expense amount if runtime error is not raised.
● This function doesn’t return anything.
def update_expense(expenses, expense_type, value):

Introduction to Software Development
● Updates the given expense type with the given value in the given expenses dictionary.
● Prints a friendly message if the expense type doesn’t exist. Note: Printing a friendly message means that the program should not raise an error or otherwise terminate.
Simply tell the user that the requested expense type does not exist and continue the
● Prints the updated expense amount if it exists.
● This function doesn’t return anything.
def sort_expenses(expenses, sorting):
● Converts the key:value pairs in the given expenses dictionary to a list of tuples and sorts based on the given sorting argument.
● If the sorting argument is the string ‘expense_type’, sorts the list of tuples based on the expense type (e.g. ‘rent’) in ascending alphabetical order, e.g. sorted results: (“coffee”, 5), (“food”, 5000), (“rent”, 1000)
● Otherwise, if the sorting argument is ‘amount’, sorts the list of tuples based on the total expense amount (e.g. 825) in descending order, e.g. sorted results: (“food”, 5000), (“rent”, 1000), (“coffee”, 5)
● Returns the list of sorted items. (Note: If the given sorting argument is not an acceptable value (e.g. ‘expense_type’ or ‘amount’), this function does nothing except print a friendly message and return None.)
def export_expenses(expenses, expense_types, file):
● Exports the given expense types from the given expenses dictionary to the given file.
● Do not append to the file. If the function is called again and the given file already exists,
make sure it overwrites what was previously in the file instead of appending to it.
● Iterates over the given expenses dictionary, filters based on the given expense types (a list of strings), and exports to a file. Skips any expense type in the given list of expense
types that doesn’t exist.
● If the expenses argument is the dictionary {“food”: 5000, “rent”: 1000, “coffee”: 5,
“clothes”: 58.92} and the expense_types argument is the list of strings ‘coffee, clothes, rent’, exports a file containing:
clothes: 58.92
rent: 1000
● If the expenses argument is the dictionary {“food”: 5000, “rent”: 1000, “coffee”: 5, “clothes”: 58.92} and the expense_types argument is the list of strings ‘coffee, clothes, sports’, exports a file containing:
clothes: 58.92
● Note, the specified expense type ‘sports’ does not exist in the expenses dictionary, so it is ignored.

● If an item is duplicated in the given expense types, don’t worry about it, just export the data as is. You should not deduplicate the expense types.
● This function doesn’t return anything. Unit Testing
To test your code, we have provided you with a SUBSET of the unit tests for this assignment in expenses_test.py. When we grade, we will run additional tests against your program. Passing the pre-submission tests does not guarantee that you will pass the post-submission tests.
Expected Output
We’ve provided the ‘template_behaviour.txt’ file to show the expected behavior of the expense management program while it’s running. For example, in the scenario below, entering “1” will allow the user to get the information for a particular expense. Entering “coffee” will show 12.4, the total for that expense. You are not required to round any numbers.
For another example, in the scenario below, entering “2” will allow the user to add an amount to an existing expense. Entering “coffee” and 1.32 will add to that expense, and show 13.72, the new total for that expense.
Introduction to Software Development

Introduction to Software Development
What to Submit
You will submit the following 4 files to Codio:
1. expenses.py: your program
2. expenses_test.py: the unit testing file
3. expenses.txt and expenses_2.txt: the .txt files to be read by your program
a. It is important that you DO NOT edit these files. If you do, you could fail the automated testing.
b. DO NOT change the spacing or remove any blank lines.
c. DO NOT copy/paste the text from these files into other files.
Evaluation
1. Did you implement the individual functions correctly in expenses.py? – 14 points
a. Does your program successfully load and parse the .txt files and store all of the
expenses in a dictionary database?
b. Can you add expenses to the system?
c. Can you update and deduct from expenses?
d. Does your program raise a RuntimeError if you try to deduct an invalid
2. Unit Testing – 10 points
a. Does your program pass all of the provided unit tests in expenses_test.py? b. Did you write the additional required test cases for each function in
expenses_test.py? Did you test both typical examples and edge cases?
3. Coding Style – 2 points
a. Appropriate naming of variables
b. Naming of helper functions (with docstrings)

Introduction to Software Development
c. Clear comments in your code

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com