Explanation :-
# First I am generating b as random number from 1 to len of biomother - 1
# Next I have initialized child_list to insert first b bits from biomother
# And then n - b bits from biofather starting from b index
# Finally after forming the child_list , I am making a final_list which has inversed bits of child_list
# Lastly returning the final_list formed.
#Function
def biochild(m,biomother,biofather):
import random
child_list = []
len_biomother = len(biomother)
b = random.randint(1,len_biomother-1)
for i in range(b):
child_list.append(biomother[i])
for i in range(b,len(biofather)):
child_list.append(biofather[i])
final_list = []
for i in child_list:
if i == 0:
final_list.append(1)
else:
final_list.append(0)
return final_list
Get Answers For Free
Most questions answered within 1 hours.