悉尼大学INFO1110课业解析

  • May 15, 2020

题意:使用python编写一个账单管理系统解析:用Python编写应用程序,该程序能够记录用户的收入和支出,能够显示余额的变化,用户能够指定时间设定收入与支出。程序需要从文件中读取信息当作起始条件,随后根据指令进行操作:trancaction:当用户输入该指令后,提示用户输入交易涉及多少钱,正数为收入,负数为支出,然后反应在余额中。next:进入第二天。但如果用户余额低于0,则打印“你欠债了”,程序结束;否则,程序应该打印到第二天,开始新的一天。status:显示到目前的情况汇总,而且回根据当前金额与起始金额与用户互动。regular:用户能够指定一些常规的收入或者指出信息。help:显示提示信息,提示用户指令的操作quit:退出程序。这是一个字符串处理的问题,当用户输出的字符串和指令相匹配则执行相应的操作,如果不是上述的所有指令则打印提示信息。涉及知识点:文件读写、字符串处理、数组更多可加微信讨论微信号:ITCSdaixiepdf全文INFO1110 / COMP9001 Assignment 1Money TrackerDeadline: 23rd Sept 2019, 11:59pm AEST (Week 8, Monday)Weighting: 10% of the final assessment markOverviewBrief DescriptionYou will write a program that allows the user to manage their finances. The program will be ableto record the user’s incomes and expenses, display how their balance has changed, etc. It will alsoneed to be able to handle regular incomes and expenses; for example, the user will be able tospecify that they have a $100 income every Sunday, or that they spend $40.50 every Thursday.Implementation detailsYour program will be written in Python 3. The only modules you may import are sys and thefunction.py file which you will write yourself.SubmissionYou will submit your code on the assignment page on Ed. To make a submission, you will need topress the “Mark” button. You may submit as many times as you wish without penalty – we willmark the last submission that you make. After each submission, the marking system willautomatically check your code against the public test cases.Please ensure you carefully follow the assignment specification. Your program output mustexactly match the output shown in the examples.Warning: Any attempts to deceive or disrupt the marking system will result in an immediate zerofor the entire assignment. Negative marks can be assigned if you do not properly follow theassignment specifications, or your code is unnecessarily or deliberately obfuscated.Help and feedbackYou are encouraged to ask questions about the assignment during the Helpdesk and on the Eddiscussion board; however, remember that you should not be posting any assignment codepublicly, as this would constitute academic dishonesty.The ProgramStarting the ProgramThe program will be given 1 extra command line argument when it is run:$ python3 tracker.py (filename)This (filename)will specify a file with information about regular incomes and expenses; see thesection on Regular Transactions for more information (it is recommended that you implementthis feature last).After handling this file, the program will ask the user for their starting balance, like so:Starting balance: $The user will then fill out this field with their initial balance, for example:Starting balance: $4.11—If the starting value cannot be converted to a float, the program should print Error:Cannot convert to float! and quit immediatelyStarting balance: $catError: Cannot convert to float!—If the starting value is negative or zero, the program should print Error: Must start withpositive balance! and quit immediately.Starting balance: $-5Error: Must start with positive balance!Once we have the regular payments and initial balance set up, we’re good to go! The programshould now continually ask for input, like so:Enter command:Depending on what the user enters, the program will record new transactions, show somestatistics, etc. For example, if the user types transaction …Enter command: transaction…then the transaction operation (explained below) should execute. The program shouldcontinue asking for more inputs indefinitely, and execute the appropriate code each time.OperationstransactionRecords a new income or expense transaction.The program should ask the user how much money was involved in the transaction, like so:Enter amount: $The user should then be able to type in how much they earned or spent. Positive values representincome, and negative values represent expenses.Enter amount: $5.95Enter amount: $-2.35This value should then be reflected in the user’s balance; for example, if they originally had $5 butmade a transaction of -$3, the user would now have $2.However, if the value the user types in cannot be converted to a float, the program should printError: Cannot convert to float! and ask for another command.Enter amount: $catError: Cannot convert to float!Enter command:nextAdvances to the next day, making sure the user is not in debt.If the user has strictly less than $0, the program should print Oh no! You’re in debt! and quitimmediately. Otherwise, it should print Going to the next day… and start a new day.In this program, we start at day 0 and increase the day number by 1 every time the nextcommand is executed.Enter amount: $Enter amount: $5.95Enter amount: $-2.35Enter amount: $catError: Cannot convert to float!Enter command:statusDisplays a summary of how the day is going so far.The program should print the following message:Day (day number) (weekday)Starting balance: $(starting balance)Current balance: $(current balance)Here,(day number) is the current day number of the program. As explained above, this starts at0 and increases by 1 for every day that passes.(weekday)is which weekday it currently is, abbeviated to three letters; Sun for Sunday,Mon for Monday, etc. In this program, day 0 is always a Sunday, day 1 is a Monday, and soon. Day 6 would be a Saturday and day 7 is a Sunday again. (The weekdays list in thescaffold may be useful here.)(starting balance) is the amount of money we had at the start of the day, before anytransactions (including regular transactions) were made. It should be displayed rounded toexactly 2 decimal places.(current balance) is the amount of money we currently have, including all thetransactions we have made that day. It should be displayed rounded to exactly 2 decimalplaces.If the current balance is greater than the starting balance, the program should also print Nicework! You’re in the black. . Conversely, if the current balance is less than the startingbalance, the program should print Be careful! You’re in the red. . If the current balance isthe same as the starting balance, no extra message needs to be printed.Here are some examples:Day 0 (Sun)Starting balance: $5.00Current balance: $6.00Nice work! You’re in the black.Day 5 (Fri)Starting balance: $55.00Current balance: $54.50Be careful! You’re in the red.Day 30 (Tue)Starting balance: $120.00Current balance: $120.00regularDisplays a summary of the regular transactions.Please see the section on “Regular Transactions” to see how these values will be specified.The program should print Regular Transactions: ; then, for every weekday, the programshould show a summary of the regular transactions in the following format:(weekday): +(regular income) -(regular expense)Here,weekday is the weekday abbreviated to three letters.regular income is the income the user regularly earns for that weekday. It should bedisplayed rounded to exactly 2 decimal places.regular expense is the expense the user regularly has for that weekday. It should bedisplayed rounded to exactly 2 decimal places.Here is an example:Regular Transactions:Sun: +$5.00 -$4.00Mon: +$3.00 -$2.00Tue: +$7.35 -$1.00Wed: +$0.00 -$0.00Thu: +$14.90 -$5.00Fri: +$6.00 -$3.00Sat: +$6.00 -$5.00helpShows a list of availabile commands.The program should print the following message:The available commands are:“transaction”: Record a new income or expense“next”: Move on to the next day“status”: Show a summary of how you’re doing today“regular”: Show a summary of your regular transactions“help”: Show this help message“quit”: Quit the programquitQuits.The program should print Bye! and quit.Anything elseIf any command other than those specified above is entered, the program should simply print thefollowing message:Command not found.Use the “help” command for a list of available commandsThe program should then continue prompting for commands.Regular TransactionsRegular transactions are incomes and expenses that are automatically made on specific days ofthe week – for example, the user might always earn $100 on Sundays and spend $40.50 onThursdays, which the program should automatically process. To implement these regulartransactions, you need to follow these three steps:Step 1: Write the function process_file in the function.py file. This function should take onestring as an argument, open the file specified by this string and read the details of the regulartransactions described in this file. You can assume that the file will always be in the followingformat, with exactly 14 lines and each line being convertible to a float without error:Sunday incomeSunday expenseMonday incomeMonday expense…Friday incomeFriday expenseSaturday incomeSaturday expenseAll values in this file will be given as positive values; so if the user had a regular income of $100 onSundays and a regular expense of $40.50 on Thursdays, our file would look like this:1000000000040.500000The function should return a tuple of two lists, both of length 7; the first one being the regularincomes throughout the week, and the second one being the regular expenses throughout theweek.For example, if the string given to the function specified the file above, it should return ([100.0,0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 40.5, 0.0, 0.0]) . Make sureyour tuple contains lists of floats, not lists of strings.However,If the file specified by the parameter doesn’t exist, the function should raise a ValueErrorwith the content of that error being the message Error: String does not represent avalid file! .Step 2: At the start of your main code, use the process_file function to get the 2 listscontaining the details of the regular incomes and expenses. The filename to be used as theparameter for this function will be specified as a command line argument when running theprogram$ python3 tracker.py filenameYou will need to make sure you include the line from function import process_file at thetop of your main code so that you can use the process_file function you wrote in part 1.However,If the required command line argument is not given, the program should print Error: Notenough command line arguments! and quit immediately.If the process_file function raises a ValueError, the program should print Error: Filenot found! and quit immediately.Step 3: Ensure your program automatically adds the regular income and subtracts the regularexpenses for the appropriate weekday at the start of every day.ExamplesRegular Transaction Filesno_regular_transactions.txt :00000000000000sample_regular_transactions.txt :54327.3510014.956365Program ExecutionsNormal Case 1:$ python3 tracker.py no_regular_transactions.txtStarting balance: $100.50Enter command: transactionEnter amount: $10Enter command: statusDay 0 (Sun)Starting balance: $100.50Current balance: $110.50Nice work! You’re in the black.Enter command: nextGoing to the next day…Enter command: statusDay 1 (Mon)Starting balance: $110.50Current balance: $110.50Enter command: regularRegular Transactions:Sun: +$0.00 -$0.00Mon: +$0.00 -$0.00Tue: +$0.00 -$0.00Wed: +$0.00 -$0.00Thu: +$0.00 -$0.00Fri: +$0.00 -$0.00Sat: +$0.00 -$0.00Enter command: transactionEnter amount: $-3Enter command: transactionEnter amount: $-10.2Enter command: statusDay 1 (Mon)Starting balance: $110.50Current balance: $97.30Be careful! You’re in the red.Enter command: quitBye!Normal Case 2:$ python3 tracker.py sample_regular_transactions.txtStarting balance: $10.00Enter command: nextGoing to the next day…Enter command: nextGoing to the next day…Enter command: nextGoing to the next day…Enter command: nextGoing to the next day…Enter command: statusDay 4 (Thu)Starting balance: $18.35Current balance: $28.25Nice work! You’re in the black.Enter command: transactionEnter amount: $100Enter command: quitBye!Invalid Command:$ python3 tracker.py no_regular_transactions.txtStarting balance: $5Enter command: STATUSCommand not found.Use the “help” command for a list of available commandsEnter command: exitCommand not found.Use the “help” command for a list of available commandsEnter command: quitBye!Going into Debt:$ python3 tracker.py no_regular_transactions.txtStarting balance: $5Enter command: transactionEnter amount: $-10Enter command: statusDay 0 (Sun)Starting balance: $5.00Current balance: $-5.00Be careful! You’re in the red.Enter command: transactionEnter amount: $6Enter command: statusDay 0 (Sun)Starting balance: $5.00Current balance: $1.00Be careful! You’re in the red.Enter command: nextGoing to the next day…Enter command: transactionEnter amount: $-10Enter command: statusDay 1 (Mon)Starting balance: $1.00Current balance: $-9.00Be careful! You’re in the red.Enter command: nextOh no! You’re in debt!Non-existent File$ python3 tracker.py nonexistent.txtError: File not found!Unable to Interpret Transaction as Float$ python3 tracker.py no_regular_transactions.txtStarting balance: $10.50Enter command: transactionEnter amount: $catError: Cannot convert to float!Enter command: quitBye!Hints and Extra InformationYou should always print an empty line directly before asking the user for a command.Commands are case-sensitive. For example, quit is valid, but QUIT is invalid.To print a string containing single quotes, enclose it in double quotes, and vice versa (or puta backslash before it).Use the modulo operator ( % ) to your advantage. It can help you keep track of weekdays!For the purposes of this assignment, you can treat all monetary values as floats – none of thetest cases will cause floating point errors.Marking7 marks will be given for passing the automated test cases. There are a total of 28 tests, andyou will receive 0.5 marks for every 2 that you pass (quarter marks will not be given).3 marks will be given for a manual inspection of code. You should ensure that your codeuses meaningful variable names, good structure, and helpful and concise comments toclarify the intentions of the code.Late SubmissionsLate submissions have a hard cap of 25% of the total possible marks per day late. For example, ifyour submission is 1 hour late, you can only receive a maximum of 75% for this assessment. Ifyour submission is 48 hours late, you can only receive a maximum of 50% for this assessment.Do not make any submissions after the deadline unless you want it to be counted as late.Remember, we will be marking the last submission you make.Academic declarationBy submitting this assignment, you declare the following:I declare that I have read and understood the University of Sydney Student Plagiarism: CourseworkPolicy and Procedure, and except where specifically acknowledged, the work contained in thisassignment/project is my own work, and has not been copied from other sources or been previouslysubmitted for award or assessment.I understand that failure to comply with the Student Plagiarism: Coursework Policy and Procedure canlead to severe penalties as outlined under Chapter 8 of the University of Sydney By-Law 1999 (asamended). These penalties may be imposed in cases where any significant portion of my submittedwork has been copied without proper acknowledgment from other sources, including published works,the Internet, existing programs, the work of other students, or work previously submitted for otherawards or assessments.I realise that I may be asked to identify those portions of the work contributed by me and required todemonstrate my knowledge of the relevant material by answering oral questions or by undertakingsupplementary work, either written or in the laboratory, in order to arrive at the final assessment mark.I acknowledge that the School of Computer Science, in assessing this assignment, may reproduce itentirely, may provide a copy to another member of faculty, and/or communicate a copy of thisassignment to a plagiarism checking service or in-house computer program, and that a copy of theassignment may be maintained by the service or the School of Computer Science for the purpose offuture plagiarism checking

LATEST POSTS
MOST POPULAR

ezAce多年来为广大留学生提供定制写作、留学文书定制、语法润色以及网课代修等服务,超过200位指导老师为您提供24小时不间断地服务。