Question

In: Computer Science

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 list must have the same length n.
 child is generated by randomly combining part of the child's information
biomother and biofather.
 The first part of the child list will be made up of the first b bits of biomother
and the second part by the last n-b bits of the biofather.
 For example, if b = 3, biomother = [1, 0, 0, 1,0,1] and biofather = [1,1,1, 0, 0, 1],
then child = [1,0,0,0,0,1].
 The value b has to be chosen randomly by the function.
 After generating child, each bit in the list is considered for mutation.
 For each bit of child, with probability m the bit is “mutated” by being replaced by its inverse
(If the bit is 0 it is replaced by 1, and if it is 1 it is replaced by 0).

 Finally, the function returns the list child.

Solutions

Expert Solution

import random

def biochild(n,biomother,biofather):    #Function biochild with parameters n,biofather and biomother
        
        b=random.randint(0,n)                           #Random value of b in range o to length of lists
        child=[]                                                        #Creating list child
        child=random.sample(biofather, b)+random.sample(biomother, n-b)         #Generating random part of biofather and biomother in consideration of b  

        for i in range(n):                                      #Mutating child by altering sequence
                if child[i]==0:                                 #If there is 0 replace by 1
                        child[i]=1
                else:
                        child[i]=0                                      #if there is 1 replace by 0
        return child                                            #return the list


biomother = [1, 0, 1, 0, 1, 1]
biofather = [0, 0, 1, 1, 1, 0]
x=biochild(6,biofather,biomother)       #Calling function biochild with parameters
print(x)

Here i have created the biochild function where the parameters are biofather, biomother and n(size). The function firstly create child list by getting random samples from both biofather and biomother with random value b. For the mutation of list I have use for loop and if statement to alter the bits(0=1 and 1-0). Finally the list is return.


Related Solutions

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...
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 phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  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)....
python practice! 1. Create a function that takes a user choice and one number as parameters...
python practice! 1. Create a function that takes a user choice and one number as parameters and returns the operation result. -Square: print the number square -Sqrt: print the square root of the number -Reverse: reverse the sign of the number (pos or neg) and print it Note: Detect invalid choices and throw an error message – Number can be anything. 2. Create a function that takes a user choice and two numbers (start and end) as parameters. For example,...
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...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters,...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters, a list of strings, and a string. This function #should return a list of all the indices at which the #string is found within the list. # #You may assume that you do not need to search inside the #items in the list; for examples: # # search_for_string(["bob", "burgers", "tina", "bob"], "bob") # -> [0,3] # search_for_string(["bob", "burgers", "tina", "bob"], "bae") # -> []...
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters....
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters. It should return True if those strings are equal WITHOUT considering the characters on the ends (the beginning character and the last character). It should return False otherwise. For example, "last" and "bask" would be considered equal without considering the characters on the ends. Don't worry about the case where the strings have fewer than three characters. Your function MUST be called same_without_ends. You...
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array...
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array of array type, a count of elements in the array, and a value. As with the remove method we discussed in class, elements passed the count of elements are stored as None. This function should remove all occurrences of value and then shift the remaining data down. The last populated element in the array should then be set to None. The function then returns...
Define a Python function named matches that has two parameters. Both parameters will be lists of...
Define a Python function named matches that has two parameters. Both parameters will be lists of ints. Both lists will have the same length. Your function should use the accumulator pattern to return a newly created list. For each index, check if the lists' entries at that index are equivalent. If the entries are equivalent, append the literal True to your accumulator. Otherwise, append the literal False to your accumulator. Hint: Since you must use the same index with each...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT