Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Implement a Gene inheritance model combining DNA

  • A class representing a person. It has an attribute called "genes" which is string of letters. Each character is a gene.
  • Implement the + operator on genes that will create a new "Person" and for the gene will select one randomly from each parent.
a = Person('ABC')
b = Person('DEF')

c = a + b
print(c.gene) # ABF