32
loading...
This website collects cookies to deliver better user experience
This program is a simple animation of DNA
import random
import sys
import time
PAUSE = 0.15 # Change it 0.0 and see what happen
import random, sys, time
it will also work.PAUSE
!Try to change it 0.0 and see what happens when change it. First use 0.15 as default then change it.
# below are the rows of DNA animation
ROWS = [
' ##',
' #{}-{}#',
' #{}---{}#',
' #{}-----{}#',
' #{}------{}#',
' #{}------{}#',
' #{}-----{}#',
' #{}---{}#',
' #{}-{}#',
' ##',
' #{}-{}#',
' #{}---{}#',
' #{}-----{}#',
' #{}------{}#',
' #{}------{}#',
' #{}-----{}#',
' #{}---{}#',
' #{}-{}#',]
#123456789 use this to measure the number of spaces
ROWS
contain a list and in this a all the structure of the DNA is in a string.123456789
.##
at 9
then going down.##
again starts but now going to right side rather left side.
try:
print('DNA Visualization || Ihtesham Haider')
print('Press CTRL-C on Keyboard to quit....')
time.sleep(2)
rowIndex = 0
#Main loop of the program || Started
while True:
#incrementing for to draw a next row:
rowIndex = rowIndex +1
if rowIndex == len(ROWS):
rowIndex = 0
# Row indexes 0 and 9 don't have nucleotides:
if rowIndex == 0 or rowIndex ==9:
print(ROWS[rowIndex])
continue
try
and except
, I will explain it to you in just a minute.randomSelection = random.randint(1,4)
if randomSelection ==1:
leftNucleotide, rightNucleotide = 'A', 'T'
elif randomSelection ==2:
leftNucleotide, rightNucleotide = 'T', 'A'
elif randomSelection ==3:
leftNucleotide, rightNucleotide = 'C', 'G'
elif randomSelection ==4:
leftNucleotide, rightNucleotide = 'G', 'C'
# priting the row
print(ROWS[rowIndex].format(leftNucleotide, rightNucleotide))
time.sleep(PAUSE)
random.randit(1,4)
1 to 4if elif
conditions to check the program for us and values at the right place.conditions = if -elif
we printed out the row and then a time module is used which we have imported and used pause for it.
# The time.sleep will add a slight pause.
except KeyboardInterrupt:
sys.exit() #This will end the program when click CTRL-C