This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpunett_square_full.py
65 lines (52 loc) · 1.76 KB
/
punett_square_full.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
######################################### PART ONE
reps = ["BB", "Bb", "bb"]
def rep2trait(rep):
assert len(rep) == 2
assert rep in reps
if (rep == "bb"):
return "Blue Eye"
else:
return "Brown Eye"
######################################### PART TWO
def possible_offsprings_reps(father, mother):
assert father in reps
assert mother in reps
offsprings = []
for allele_father in father:
for allele_mother in mother:
offsprings += [allele_father+allele_mother]
return offsprings
######################################### PART FUN
# Pretty printing for a punnett square
## print as a 3*3 two dimensional array
def punnett_square(father, mother):
## play it around > _ <
# >>> punnett_square("BB", "BB")
# \ B B
# B BB BB
# B BB BB
# >>> punnett_square("BB", "bb")
# \ b b
# B Bb Bb
# B Bb Bb
# >>> punnett_square("Bb", "bb")
# \ b b
# B Bb Bb
# b bb bb
# why do we not need assertion checks here?
pors = possible_offsprings_reps(father, mother)
# is the order correct?
square = [['\\', mother[0], mother[1]],
[father[0], pors[0], pors[1]],
[father[1], pors[2], pors[3]]]
print('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in square]))
######################################### PART EXTRA FUN
# Have you thought of how to print all punnett_squares?
## Let's use a nested loop
## why don't we use a list comprehension
## can you think of ways to use list comprehension
def all_punnett_squares():
for father in reps:
for mother in reps:
punnett_square(father, mother)
print() #Blank line after a square