Control Flows and Loops

  • Example 1: deciding palindrome sequences from many candidates

In [1]: manyseqs=['ACTGATG','ACTGGTCA','ATGATG','TCGAAGCT','GCAGGCG','GATCCTAG','CATGTCGT','CTCTATCTC']
In [2]: for seq in manyseqs:
   ...:     if (seq==seq[::-1]):
   ...:         print(seq)
   ...:         
ACTGGTCA
TCGAAGCT
GATCCTAG
CTCTATCTC
  • Example 2: print odd numbers 1 to 20

In [1]: for i in range(1,21):
   ...:     if (i%2==1) :
   ...:         print("%02d" %i)
   ...:         
01
03
05
07
09
11
13
15
17
19

Last updated

Massachusetts Institute of Technology