Kodomo

Пользователь

Решение заданий практикума №7

aminoacid.py

   1 k = input('Enter the aminoacid name: ')
   2 k = k.upper()
   3 
   4 aro = {'F', 'W', 'Y'}
   5 ali = {'A', 'G','I', 'L', 'V'}
   6 al = {'A', 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'P', 'S', 'T', 'W', 'Y', 'V'}
   7 
   8 while k not in al:
   9     k = input('Error. Try again: ').upper()
  10 
  11 if k in aro:
  12     print('aromatic')
  13 elif k in ali:
  14     print('aliphatic')
  15 else:
  16     print('other')

squares.py

   1 k = int(input('Enter a number: '))
   2 i = 1
   3 while i**2 < k:
   4     print(i**2)
   5     i += 1

power-of-three.py

   1 n = int(input('Enter a positive integer number: '))
   2 k = n
   3 while k > 1:
   4     k = k / 3
   5 if k == 1.0:
   6     print('TRUE')
   7 else:
   8     print('FALSE')

head.py

   1 name = input('Enter a file name: ')
   2 n = int(input('Enter a number of lines to output: '))
   3 f = open(name, "r")
   4 line = f.readline()
   5 i = 1
   6 while i <= n:
   7     if line == '':
   8         break
   9     print(line.strip('\n'))
  10     line = f.readline()
  11     i += 1
  12 
  13 f.close()

grep.py

   1 name = input('Enter a file name: ')
   2 k = input('Enter a fragment: ')
   3 f = open(name, "r")
   4 for line in f:
   5     if k in line:
   6         print(line.strip('\n'))
   7 
   8 f.close()

seqnames.py

   1 inp = open('input-seqnames.fasta', "r")
   2 
   3 out = open('output-seqnames.txt', "w")
   4 
   5 for line in inp:
   6     if '>' in line:
   7         out.write(line[1:line.index(" ")])
   8         out.write("\n")

average.py

   1 f = open('input-average.txt', "r")
   2 s = 0
   3 n = 0
   4 l = []
   5 
   6 for line in f:
   7     line = line.strip()
   8     l.append(line)
   9 
  10 for i in l:
  11     if i != '':
  12         s += float(i)
  13         n += 1
  14 
  15 print('The arithmetic mean of the numbers in the file is ' ,s/n, '.', sep='')