Question

In: Computer Science

Creates a function called pick. The function receives a "string" representing one year (the variable with...

Creates a function called pick. The function receives a "string" representing one year (the variable with this "string" will be called uve) and a list containing "strings" representing bank accounts (call this bera list). <br>
• Each account is represented by 8 characters. The format of each account number is "**-**-**", where asterisks are replaced by numeric characters. o
For example, "59-04-23".
• The two central characters of the "string" for each account represent the year the account was created. o
For example, the account "59-04-23" was created in 2004.
Presumes that every year they are from 2000 onwards.
• The year in uve is represented by four characters. o
Example,"2001"
• The feature must return a list of all accounts that were created in the year indicated in uve, with each<br>t without the "-" symbols.<br> o
For example, if the accounts are ["49-01-26", "19-01-33", "99-01-53", "59-04-23"] and the year of interest is<br>"2001", then the function must return ["490126", "190133", "990153"]; note that the accounts follow<br>in the form of "string".<br>
• In addition, the function must return the percent of accounts that were created in the year indicated by uve. <br>
For example, if the accounts are ["49-01-26", "19-01-33", "99-01-53", "59-04-23"] and the year of interest is "2001", then the function should return 75% (three accounts were created in 2001, and there are four<br>accounts, therefore 100 x 3 x 75%)

Python(programming language)

Solutions

Expert Solution

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!


Related Solutions

In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks...
Function 6: Sorting string function name (str) a. This function receives an string. Your task is...
Function 6: Sorting string function name (str) a. This function receives an string. Your task is loop through the each character of the string and separate all digists/letters/special characters. Display all digits at the beginning, followed by letters then the special chars and display result in console. For example if following string is passed to this function “ha1m2i3:n)” Result should be: 123hamin:)
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special...
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special characters), possibly empty, and returns a new string containing the following. a) in those positions where the original string has an even digit, the corresponding character in the new (returned) string should have the string digit '0' b) in those positions where the original string has a vowel letter (upper or lower case), the new (returned) string should have the letter 'V'. Note that...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String variable called myString1 and initialize it to "Programming". C) Declare a String variable called myString2 and initialize it to "Language". D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".". E) Print the sum of the lengths of myString1 and myString2 (must call the length() method). F) Print the 2nd, 4th, and 7th character...
Creates a function called biochild. The function has as parameters the number m and lists biomotℎer...
Creates a function called biochild. The function has as parameters the number m and lists biomotℎer and biofatℎer. The lists biomotℎer and biofatℎer contain 0’s and 1’s. For example: biomotℎer = [1,0,0,1,0,1] and biofatℎer = [1,1,1,0,0,1] Both lists have the same length n. The 0’s and 1’s represent bits of information (remember that a bit is 0 or 1). The function has to generate a new list (child). The child list has to have the same length n. child is...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' //...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' // This variable should be assigned a new object // In this object create three key:value pairs // The keys should be: 'name', 'city', 'favoriteAnimal' // The values should be strings associated with the keys. // return the variable 'aboutMe' } function exerciseTwo(animal){ // Exercise Two: In this exercise you will be given an object called 'animal' // Create a new variable called 'animalName' //...
Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the...
Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the corresponding binary number. Do the conversion by repeatedly dividing the number n by 2 using integer division, keepting track of the remainders, until the number is reduced to 0. The remainders written in reverse order form the binary number string. Do integer division of 5 by 2, so that N//2 is 2 with remainder 1. Now divide 2 by 2 to get 1 with...
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT