In this assignment, you will write multiple functions in a single python file na
ID: 3854832 • Letter: I
Question
In this assignment, you will write multiple functions in a single python file named banking.py. Each of the functions will compute operations that a bank might need/want to know. In this assignment, you are not implementing a complete bank-account management system. Instead, you are going to write individual functions, that complete very specific bank-related tasks. You should call the functions to test that they are working correctly. However, when you submit banking.py, do not leave any calls to the functions in there. The contents of the file should be only the function definitions. No need for a main() function. You must use loops (while or for) to implement each of these functions except for min_max_account. You should not use the sum(), min() or max() built-in python functions. You may use sort().
Write a function named sum_of_all_accounts. This function will have one parameter, named whatever you like, which you can assume will be a list of integers representing bank account values in US dollars. This function will compute the sum of all of the accounts. The sum will be returned by the function. Write a function named min_max_account. This function will take one parameter, named whatever you choose, which you can assume is a list of integers representing bank account values in US dollars. This function will determine the smallest (minimum) and largest (maximum) bank account. Once the two numbers are determined, it will print them both out like so:
But, instead of just printing X and Y, print the actual numeric values of the accounts.
Write a function named get_max_customer. This function will have two parameters: The first is a list of integers representing bank account values in US dollars. The second is a list will be the same length as acct_values, and has the owner name that correspond with each value in the other list. For example, the first argument might be the list [1000, 1500, 1200, 3000] and the second argument could be: ['Jim', 'Alex', 'Jane', 'Anne']. This means that Jim has $1000 in his account, Alex has $1500 in his, Jane has $1200 in hers, and Anne has 3000 in hers.
This function will return the name of the bank customer with the highest valued account. Write a function named report_all_acct_info. This function will have two parameters (the same parameters as get_max_customer): This function will print out a “report” to the python console with the name and corresponding account value for each account passed to the function. For example, if the first parameter is [100, 200, 450] and the second is [ 'John', 'Bill', 'Samuel' ], then the function will print the following when called:
Write a function named report_acct_info. This function will take three total parameters. The first two will be the same as the previous two problems. The third one will be a single integer named minimum. This function will print out a similar report to the last problem. However, it will only print out accounts that have a dollar amount greater than than the minimum integer. For example, if the first parameter is [100, 700, 900, 200, 450], the second is ['Jane', 'Ally', 'Bill', 'Will', 'Samuel'], and the third is 400, then the function will print the following when called:
Explanation / Answer
Code:
#!/usr/local/bin/python3
# function to sum all the accounts in a given list
def sum_of_all_accounts(act_list):
sum = 0
# iterating through list to sum the account values
for i in range(0, len(act_list)):
sum += act_list[i]
return sum
# function to determine max and min accounts
def min_max_account(act_list):
min_max_list = []
# assign the first value as default max and min
min = max = act_list[0]
# iterating through list to determine max and min
for i in range(0, len(act_list)):
x = act_list[i]
if (x > max):
max = x
if (x < min):
min = x
min_max_list.append(min)
min_max_list.append(max)
return min_max_list
# function to get max customer
def get_max_customer(act_list, act_name):
max = act_list[0]
# iterating through list to determine maximum account customer index
for i in range(0, len(act_list)):
x = act_list[i]
if(x > max):
max = i
return act_name[i]
# function to print all the users account information
def report_all_acct_info(act_name, act_list):
print('All accounts')
for i in range(0, len(act_list)):
print(" ",act_name[i]+"'s bank account has $"+str(act_list[i]))
# function to print users account information only for accounts greater than a given value
def report_acct_info(act_name, act_list, min):
print('All accounts valued greater than', min)
for i in range(0, len(act_list)):
if act_list[i] > min:
print(" ",act_name[i]+"'s bank account has $"+str(act_list[i]))
if __name__=='__main__':
all_accts = (100, 700, 900, 200, 450)
result = sum_of_all_accounts(all_accts)
print('Sum of all accounts is: ', str(result))
result = min_max_account(all_accts)
print('The min bank account is: ', str(result[0]))
print('The max bank account is: ', str(result[1]))
act_names = ('Jim', 'Alex', 'Jane', 'Anne')
act_value = (1000, 1500, 1200, 3000)
result = get_max_customer(act_value, act_names)
print('Bank customer with high value account is: ', str(result))
report_all_acct_info(act_names, act_value)
act_names = ('Jane', 'Ally', 'Bill', 'Will', 'Samuel')
act_value = (100, 700, 900, 200, 450)
report_acct_info(act_names, act_value, 400)
Code is captured in the link http://pasted.co/bebf1f1a in case if you have any problems with the code pasted above.
Execution screenshot is captured in the link https://pasteboard.co/GzUgtMM.png. pleaese check.
Execution and output:
Unix Terminal> python3 banking.py
Sum of all accounts is: 2350
The min bank account is: 100
The max bank account is: 900
Bank customer with high value account is: Anne
All accounts
Jim's bank account has $1000
Alex's bank account has $1500
Jane's bank account has $1200
Anne's bank account has $3000
All accounts valued greater than 400
Ally's bank account has $700
Bill's bank account has $900
Samuel's bank account has $450
Unix Terminal>