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 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 ??????...
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...
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
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...
Complete the Python function called 'greetings(time)' that accepts a time in "HH:MM" format as a string....
Complete the Python function called 'greetings(time)' that accepts a time in "HH:MM" format as a string. The function should return a greeting message based on the hour given in the time object as follow: If the time is before noon: 'Good Morning.', if it is in the afternoon: 'Good Day.' Please use the following template for your python script to define the greetings() function and name it as mt_q3.py. Replace the place holder [seneca_id] with your Seneca email user name....
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...
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