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") # -> []...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
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...
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT