Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write down the code of Python Introduction: You've been given CSV (comma separated values) files that represent the contents of a bank, including the

Please write down the code of Python
image text in transcribed
image text in transcribed
image text in transcribed
Introduction: You've been given CSV (comma separated values) files that represent the contents of a bank, including the names and balances associated with each account. Your objective is to find the two accounts with the smallest difference between their balances. The purpose of this assignment is to check your understanding of basic Python programming, especially file //O, strings, functions, and lists. Mastery of Python is not necessary to succeed in CSCl4041, since programming is not the focus of the class; if you understand how to use the concepts listed above, you should be fine. This should be a straightforward assignment, so if you find yourself struggling, I encourage you to ask for Python help during office hours or via email. Download the ZIP file pa01files. zip from Canvas, and unzip it. This contains six sample CSV files (bank1.csv, bank2.csv, bank3.csv, bank4.csv, bank5.csv, bank6.csv). You can open them in a spreadsheet program like Excel or Google Sheets to see the tabular data each represents in a nice format, but I would suggest opening it at least once in a text editor to remind yourself of how the data is truly represented: as a text file where each line is a row with comma-separated columns. While there will be additional CSV files used for tests on Gradescope, you can assume the following about their contents: - The first row of the CSV file will contain the header for each column: all subsequent rows will contain information for one bank account. - The CSV file will have three columns, in this order: Name, Balance, Account Number - The CSV file will contain at least two accounts (so at least three rows) - Every account will have a unique name and number associated with it - There will not be a tle between two pairs of accounts for the minimum difference in balance, nor will any two accounts have the same balance. The zip folder should also contain a template file pa01.py. This is what you'll be editing and turning in to Gradescope at the end: the CSV files do not need to be submitted. The file contains one function, find_closest (filename), that you will need to complete in order to recelve credit for the assignment. The function should take in a single parameter, a string representing the name of a CSV file (assumed to be in the same directory). It should read in the data from that file, determine which two accounts have the minimum difference between their balances, and return a list of two strings representing the names attached to those two accounts. The order of the names does not matter. For example, here is the contents of bank1.csv: Name, Balance, Account Number Scrooge McDuck, 10000000000,315515 Macklemore, 20, 506334 Loch Ness Monster, 3.5,699157 college student, 78000,573699 For a more clear plcture of the data, here is what it would look like if you opened it in Excel: Since the two accounts with the smallest difference between their balances belong to Macklemore and the Loch Ness Monster (a difference of 20 - (3.5), or 23.5), running find_closest("bank1.csv') should return ['Macklemore', 'Loch Ness Monster'] (or ['Loch Ness Monster", 'Macklemore']) Hints: - As with any programming task, use print statements to debug logic errors - You can ignore the Account Number column entirely for this problem - If you plan to compare every account balance against every other account balance, be - sure to avoid comparing an account to itself - You're going to need some way to associate each name with the appropriate balance: consider using structures like tuples, dictionaries, or user-defined classes. Constraints: - You are not permitted to use the input() function as this will break the grading script. - You are only permitted to import modules that exist on the Gradescope VMs, which should be most of the Python Standard Library: hitps://docs python.org/3/ibraryl. You'll know if your module is not present on Gradescope because you'll get an appropriate error message when Gradescope runs the test cases. - You should have no code outside of the find_closest function aside from import statements. - Exception: if you want to put in test code, you can include an if name_=. main : : block, since the Gradescope tests will ignore that code. See https://stackoverflowicom/questions/419163/what-does-if-name-main-do if you're unclear on what the above if statement does. - You may use any strategy you want to complete the task, so long as it doesn't break the above requirements. We're not testing for runtime efficlency just yet. - Your program must run without errors or infinite loops on Python 3 (any 3 .x version should usually work). After submitting to Gradescope, make sure that the test cases finish running and do not cause any errors before leaving the page

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Compute an expression for P max t1st2 B(s) > x

Answered: 1 week ago

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago