File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -206,22 +206,36 @@ cos(pi) is -1.0
206206
207207
208208> ## Jigsaw Puzzle (Parson's Problem) Programming Example
209- >
209+ >
210210> Rearrange the following statements so that a random
211- > DNA base is printed. Not all statements may be needed. Feel free to use/add
212- > intermediate variables.
211+ > DNA base is printed. Not all statements may be needed. Feel free to use/add
212+ > intermediate variables.
213213>
214214> ~~~
215215> bases="ACTTGCTTGAC"
216216> import math
217217> import random
218- > len(bases)
219- > len(bases)+1
220- > math.floor(s1)
221- > math.ceil(s1)
218+ > ___ = math.floor(s1)
219+ > ___ = len(bases)
222220> print("random base ",bases[])
223- > random.random()*l
221+ > ___ = random.random()*l
224222> ~~~
223+ > {: .python}
224+ >
225+ > > ## Solution
226+ > >
227+ > > ~~~
228+ > > import math
229+ > > import random
230+ > > bases="ACTTGCTTGAC"
231+ > > l = len(bases)
232+ > > s1 = random.random()*l
233+ > > idx = math.floor(s1)
234+ > > print("random base ",bases[idx])
235+ > > ~~~
236+ > > {: .python}
237+ > >
238+ > {: .solution}
225239{: .challenge}
226240
227241> ## When Is Help Available?
@@ -284,7 +298,7 @@ cos(pi) is -1.0
284298> ## There Are Many Ways To Import Libraries!
285299>
286300> Match the following print statements with the appropriate library calls.
287- >
301+ >
288302> Print commands:
289303>
290304> 1. `print("sin(pi/2) =",sin(pi/2))`
You can’t perform that action at this time.
0 commit comments