Question

In: Computer Science

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 represent the year in which the account was created.

o For example, the account “59-04-23” was created in 2004.

o Assume that all years are from the year 2000 onwards.

• The year in uve is represented by four characters.

o For example, "2001"

• The function must return a list with all the accounts that were created in the year indicated in ???, with each counts without the “-“ symbols.

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 "2001", then the function should return ["490126", "190133", "990153"]; note that the accounts continue in the form of a "string".

• In addition, the function must return the percentage of accounts that were created in the year indicated by ???.

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 "2001", so the function should return 75% (three accounts were created in 2001, and there are four accounts, therefore 100 × 3/4 = 75%)

Solutions

Expert Solution

Solution:

The code is in ython 3.

For percentage I typecasted as str(int(percent)) to return percentage without any decimal ponts.

If you need a different format please comment and will do the needful.

I have also added comments in the code for understanding

Code:

def pic(uve,bere):
    year=uve[2:4]
    accounts=[]
    #iterating all accounts
    for x in bere:
        #if accounts matches the year
        if(x[3:5]==year):
            #append the account and remove '-'s
            accounts.append(x.replace('-',''))
    percent=100*len(accounts)/len(bere)
    #To print percent exacyly without decimls along with '%'
    percentage=str(int(percent))+'%'
    #returning both accounts and percentage
    return accounts,percentage

#Code for testing     
accounts,percentage=pic("2001",["49-01-26", "19-01-33", "99-01-53", "59-04-23"])
print(accounts)
print(percentage)

Screenshot of sample output and code:


Related Solutions

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...
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....
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The...
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The decryption does not change the lowercase letters ‘e’, ‘w’, and ‘l’ (lowercase L). For any other character, we change it to a number using ord(). We then take the number to a power of 19, and then find the remainder after diving by 201. Finally, we take the character corresponding to the number we obtained (using chr()). For example, assume that we receive the...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Using Python provide the implementation of a function called "isAdjacent" that accepts a string.   The function...
Using Python provide the implementation of a function called "isAdjacent" that accepts a string.   The function checks if two adjacent characters in the string are the same; if they are the same, then return True otherwise return False.   The function should ignore case and check for non-empty string.  If it's an empty string, then return the message 'Empty string'. Sample runs: print( isAdjacent('ApPle')) # True print( isAdjacent('Python')) # False print( isAdjacent('')) # Empty string
Python. Create a function that receives the name of an auto maker and returns a slice...
Python. Create a function that receives the name of an auto maker and returns a slice of the dataframe with the cars from that auto maker. For instance, it may receive 'ford' and return a slice with all the cars produced by 'ford' meaning they have 'ford' in their name. Call the function for 'ford' to see if it works properly. Hint: You may create a list comprehension producing a list of all the index labels that include the auto-maker's...
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [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...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
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:)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT