In [2]:
for t in range(41):
if t % 5 == 0:
print(t+273.15)
In [4]:
for t in range(0,41,5):
print(t+273.15)
In [ ]:
for n in range(26):
#Finish
Now, instead of printing, generate a list of all the multiples of 3 from 0 to 25 that are not multiples of 5 or 7.
In [ ]:
In [2]:
for i in range(10):
print('before:', i)
if i==3 or i==7: i=i+2 #Tying to skip values 4 and 8...
print('after: ',i)
print('----------')
From the previous example you should deduce that it is better not to modify the loop variable. So now translate the previous incorrect loop into into a while loop that really skips i==4 and i==8.
In [ ]:
You have a list that should act as a kind of queueing system:
queue=['Mariona','Ramon', 'Joan', 'Quique', 'Laia']
You want to do something (say print it) with each element of the list, and then remove it form the list. (pop can be a useful method). Check that at the and, the list is empty.
In [12]:
queue=['Mariona','Ramon', 'Joan', 'Quique', 'Laia']
while queue:
print("popping name : ",queue.pop(0), "remaining", queue)
In [6]:
queue.pop(0), queue
Out[6]:
In [5]:
import math
In [7]:
math.factorial(100)
Out[7]:
In [8]:
result = 1
for i in range(100):
result = result*(i+1)
result
Out[8]:
In [12]:
result = 1
for i in range(1,101):
result = result*i
result = str(result)
suma = 0
for caracter in result:
suma = suma + int(caracter)
suma
Out[12]:
Soft software use keyword to define the type of calculations to be performed. As an example, here we will use the quantum chemistry software Gaussian. Imagine we have stored Gaussian keywords in a dictionary as in:
keywords={'basis':'6-31+G', 'SCF':['XQC', 'Tight'], 'Opt':['TS', 'NoEigenTest']}
Check that if there is a diffuse function in the basis set, SCF has 'tight' as one of its keywords.
In [ ]:
# Check different possibilities
keywords={'basis':'6-31+G', 'SCF':['XQC', 'Tight'], 'Opt':['TS', 'NoEigenTest']}
#keywords={'basis':'6-31G', 'SCF':['XQC', 'Tight'], 'Opt':['TS', 'NoEigenTest']}
#keywords={'basis':'6-31+G', 'SCF':['XQC',], 'Opt':['TS', 'NoEigenTest']}
#keywords={'basis':'6-31+G', 'Opt':['TS', 'NoEigenTest']}
if #Finish...
print('When using diffuse functions, "Tight" should be used in the SCF!')
What happens if the 'SCF' keyword is not present as in here?
keywords={'basis':'6-31+G', 'Opt':['TS, 'NoEigenTest']}
In [ ]:
#Finish
In [ ]:
def common_keys(d1, d2):
"""
Return the keys shared by dictionaries d1 and d2
returns a set
"""
#Finish
#Test it
d1 = makedict(red=1, green=2, blue=3)
d2 = makedict(purple=3, green=5, blue=6, yellow=1)
print(common_keys(d1, d2))
In [ ]:
gencode = {
'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',
'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',
'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',
'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',
'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',
'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',
'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',
'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',
'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',
'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A',
'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E',
'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G',
'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S',
'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L',
'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_',
'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W'}
Remember that you can iterate a dictionary keys with: for k in gencode: and its values with: for v in gencode.values(): Or access the values like this:
for k in d:
v =d[k]
This exercice has many possible solutions.
In [ ]:
How many of Leu(L) codons differ in only one point mutations from a Ile(I) codon?
In [ ]:
#Finish
In [ ]: