In: Computer Science
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation please refer
code Images
Typed Code:
# A function called pick with input parameters
# uve a string representing the year
# bera_list is list containing strings representing bank
accounts
def pick( uve, bera_list):
# An Empty List Accounts to
# store account number created in uve year
Accounts = [];
# a for loop to access all the strings in bera_list
for x in bera_list:
# Middle 2 digits of account number representing year are
x[3:5]
# Last two digits of given uve year are uve[2:]
# comparing whether both are equal or not
if(x[3:5] == uve[2:]):
# if they are equal
# replacing the underscores with "" (blank)
# and appending x to List Accounts
Accounts.append(x.replace('-',""))
# Calculating the Percentage of Accounts
Accounts_Percentage = (len(Accounts)/len(bera)) * 100
# returning the List of Accounts and Accounts_Percentage
return Accounts,Accounts_Percentage
# A list of bank accounts
bera=["49-01-26", "19-01-33", "99-01-53", "59-04-23"]
# A string representing the year
uve="2001"
# calling the function pick with parameters uve string and bera
List
# storing the returned values in Accounts and Percentage
Accounts,Percentage= pick(uve,bera)
# printing the returned List
print("The Bank Accounts created in the
Year",uve,"are",Accounts)
# printing The returned Percentage
print("The Percentage of Accounts is ",Percentage,"%")
#code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!