I need the code to be very simple and beginner level so that I can explain it in case asked. Money Matters. Create a Budget Planner. Overview Tracking expenses is an essential component of developing...

1 answer below »



I need the code to be very simple and beginner level so that I can explain it in case asked.



Money Matters. Create a Budget Planner.



Overview


Tracking expenses is an essential component of developing healthy financial skills, especially when budgets are limited! Many students do not track expenses because it is time consuming. They may end up spending too much money on unnecessary purchases.For this assignment, you will use Python to solve this problem. You will build a tool that can help you plan your budget.



Algorithm Description


Devise an algorithm that takes your monthly budget, the amount of money you wish to save, and a list of the prices of all the items you might need to buy during the month with a priority value (for example, from 1 to 10, with 10 being the highest priority item) to describe how much you need that item. The algorithm then should give you a plan of what to buy and what not to buy based on your priority. The algorithm can divide the items list into sections to make prioritizing more efficient. For example, the algorithm can have a list of needs and a list of wants, and the list of needs can be divided into more sections (education, food, medicine, etc) and the same for the list of wants (trips, desserts, parties, etc).




Describe your algorithmic approach



  • Describe the input(s), output(s) and the process of the algorithm.

  • Draw a flowchart to show the process of the algorithm.

  • Explain how this process is an “algorithm”.


You will be graded on#algorithmicstrategiesand** #computationaltools**




Implementation


Using an appropriatedata structure(Lists or any other data structure that you are familiar with) build a user-friendly Python program that practically implements your algorithm. The program should at minimum ask the user to input:



  • The monthly budget

  • The amount of money to be saved

  • A list of the “needs” for the month (including the price of each item)

  • A list of the “wants” for the month (including the price of each item)

  • A priority value for each item to help the program understands the priorities of the user


Using sorting, the program should return an ordered list of the items that you should buy to fit your budget and have the required savings.Provide a well-commented Python code that follows the above instructions. Make sure to include few test-cases to make sure your code works



  • Be sure to comment thoroughly so that it is clear that you understand what every line of the code is intended to accomplish.

  • Include your test cases in your submission. Explain how you used these test cases in your comments.

  • You should use the following Python skills at a minimum, but you are free to use additional skills:




Answered 1 days AfterOct 28, 2021

Answer To: I need the code to be very simple and beginner level so that I can explain it in case asked. Money...

Vaibhav answered on Oct 30 2021
115 Votes
Assignment/Algorithm.png
Assignment/Assignment 2 notebook.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Important Note For guidance on how to write in markdown, please consult [this documentation](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Introduction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are two categories of items added to the budget planner:\n",
"1. Needs are items and services that are essential for the survival and cannot be avoided.\n",
"2. Wants are items and services that are nice to have, but that one can live without them.\n",
"\n",
"Hence, needs will always be considered as a part of the what to have and can never be skipped. But, wants contains list of items or services like watching
movie, pizza, etc. which can be avoided to achieve the desired savings."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.1 Step-By-Step Algorithm\n",
"Use the cell below to demonstrate your understanding of the problem. Make sure to explain in detail how your algorithm works including the inputs, the outputs and the processes used.\n",
"\n",
"**Note: Make sure that you explain which data structure you chose and justify your choice**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The algorithm to implement a budget planner requires following inputs from the user:\n",
"
    \n",
    "
  1. Monthly budget amount
  2. \n",
    "
  3. Amount of money to be saved.
  4. \n",
    "
  5. Total number of items that are considered as needs.
  6. \n",
    "
  7. Total number of items that are considered as wants.
  8. \n",
    "
  9. For each item of the list (needs and wants) following 3 fields are required:
  10. \n",
    "
      \n",
      "
    1. Item/Service name
    2. \n",
      "
    3. Price/Cost associated with it.
    4. \n",
      "
    5. It's priority on a scale of 1(lowest) to 10(highest)
    6. \n",
      "
    \n",
    "
\n",
"\n",
"As each item will be stored in a sequential manner, i've used list data structure to store the items in the respective lists. \n",
"\n",
"Each item in the list will store 3 fields associated with it. Hence, for this i've used tuple data structure.\n",
"\n",
"#### After the user has entered all the required information, the algorithm works as follows:\n",
"
    \n",
    "
  1. Sort the two lists which contain details about items which are needed and wanted in descending order by priority and ascending order by it's price.
  2. \n",
    "
  3. Initially set balance to the monthlyBudget.
  4. \n",
    "
  5. Keep adding the items of the needsList to whatToBuy list and keep decrementing the balance.
  6. \n",
    "
  7. After all the items from the needs list have been added to what to buy, check if balance is greater than the amount of money to be saved. If so, then add the items from the wants list and keep reducing the balance with the price of the item. Else add the item to list of what not to buy list.
  8. \n",
    "
  9. Once both the lists have been processed, display the list of items which user can buy (whatToBuy) and which the user can skip buying to achieve desired savings (whatNotToBuy).
  10. \n",
    "
  11. If at some point, while adding the items from the needsList, if the value of balance becomes negative, then it means that the budget for the month is too low and even the essentails cannot be purchased.
  12. \n",
    "
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.2 Flowchart Diagram\n",
"Use the cell below to upload the flowchart that shows how the algorithm works (the visual representation of your algorithm).\n",
"\n",
"\n",
"**NOTE:** Let \"my_image.png\" be an image which is in the same directory as your jupyter notebook. If you would like to include that image on this notebook, then you can simply write in a code cell:\n",
"\n",
"```from IPython.display import Image\n",
"Image(\"my_image.png\")```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# to upload your image, replace \"my_image.png\" with the name of your image\n",
"from IPython.display import Image\n",
"Image(\"Algorithm.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.3 Explanation\n",
" Use the cell below to include a clear explanation of your algorithm. In your explanation, explain how this process is an **algorithm** and make sure to add details about how your flowchart demonstrates the different steps of the algorithm. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The algorithm process each item of the needs list of needs and adds them to the list.\n",
"It then processes each item from the list of wants and adds them to the list. Once, all the items have been added, ensure that if at any point the balance becomes equal to the savings needed, then add the remaining items to the list of **whatNotToBuy**."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Implementation\n",
"In this section, you will implement in Python the algorithm that you described above."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.1 Libraries and modules\n",
"Use the cell below to import all the libraries or modules that your Python program requires."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As i've used only the builtins, no additional library imports are required."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.2 User Input\n",
"Use the cell below to write the code that takes the user's input. Your code should allow the user to enter at least the following:\n",
"- The monthly budget\n",
"- The amount of money they want to save\n",
"- The items that they might buy during the month (needs and wants) and:\n",
" - The price of each item\n",
" - A priority value for each item (from 1 to 10, with 10 being higher priority)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Budget stores the monthly budget.\n",
"budget = int(input(\"Enter your monthly budget : $\"))\n",
"\n",
"# It contains the amount of money the user wishes to save.\n",
"savingsNeeded = int(input(\"Enter the amount of money to be saved : $\"))\n",
"\n",
"# It stores the count of total number of items the user believes are essential\n",
"needs = int(\n",
" input(\"Enter the number of items to be added to the list of needs. Example: \\\n",
" \\n Education, \\n Food, \\n Medicine, \\n Transportation etc.\\n ---> \"))\n",
"\n",
"# This will store the total number of items the user believes can be skipped to achieve desired savings.\n",
"wants = int(\n",
" input(\"Enter the number of items to be added to the list of wants. Example: \\\n",
" \\n Trips, \\n Deserts, \\n Parties: \\n---> \"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def addItems(listSize):\n",
" '''\n",
" Adds tuples to the list of items and returns the list.\n",
" This is a commen method used to store items for both needsList and wantsList.\n",
" '''\n",
" listOfItem = []\n",
" for i in range(0, listSize):\n",
" name = input(\"Enter the name of the item : \")\n",
" price = float(input(\"Enter the amount : $\"))\n",
" priority = int(input(\n",
" \"Enter the priority of this item on a scale of 1(lowest) to 10(highest) : \"))\n",
" # append the new item to the list.\n",
" listOfItem.append((name, price, priority))\n",
" return listOfItem"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.3 Sorting Functions\n",
"Use the cell below to define all the functions that will take the user's input from the cell above and then process it to make the monthly budget plan for the user. The output should contain information on what the user should buy and what not to buy."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The lists will store the respective lists.\n",
"needsList = []\n",
"wantsList = []\n",
"\n",
"# Add items to the needsList\n",
"print(\"Enter the items to be added to the list of needs. \")\n",
"needsList = addItems(needs)\n",
"\n",
"# Add items to the wantsList\n",
"print()\n",
"print(\"Enter the items to be added to the list of wants. \")\n",
"wantsList = addItems(wants)\n",
"\n",
"# sort the list of needs in decreasing order of priority and increasing order of price.\n",
"needsList.sort(key=lambda x: (x[1], -1*x[2]))\n",
"\n",
"# sort the list of wants in decreasing order of priority and increasing order of price.\n",
"wantsList.sort(key=lambda x: (x[1], -1*x[2]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def budgetPlannerAlgorithm(budget, savingsNeeded, needsList, wantsList):\n",
" balance = budget\n",
" needs = len(needsList)\n",
" wants = len(wantsList)\n",
" whatToBuy = []\n",
" whatNotToBuy = []\n",
" i = 0\n",
" # add all the items in the needsList to the whatToBuy and update the remaining balance.\n",
" while(i < needs):\n",
" whatToBuy.append(needsList[i])\n",
" balance -= needsList[i][1]\n",
" i += 1\n",
" \n",
" # If after adding the needs to whatToBuy, the balance is still greater than savingsNeeded,\n",
" # add them to whatToBuy until balance is greater than savingsNeeded.\n",
" # If the balance is already less than savings needed, add all items to whatNotToBuy list.\n",
" if(balance > savingsNeeded):\n",
" i = 0\n",
" # Add items from wants to the list based on condition.\n",
" while(i < wants):\n",
" # only add item if after adding it, the balance will be still greater than or equal to savings needed\n",
" if(balance - wantsList[i][1] >= savingsNeeded):\n",
" whatToBuy.append(wantsList[i])\n",
" balance -= wantsList[i][1]\n",
" else:\n",
" whatNotToBuy.append(wantsList[i])\n",
" i += 1\n",
" else:\n",
" whatNotToBuy += wantsList\n",
" \n",
" # If balance...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here