# Jak pracovat s timto ukolem: # How work with this homework: # Dle zadani dopiste funkcionalitu k jednotlivym funkcem. # Write functionality for each function based on description. # Napriklad nasledujici funkce bude vracet v kazdem pripade True. # For example next function called show_case must return True in any case. # Pokud bude pouzivat funkci print pro odladovani kodu, nezapomnte ji pak pred odevzdanim smazat. # If you use function print to tune your code, don't forget removing it from code before submitting. def show_case(): return False # # Domaci ukol 04 # Homework 04 # # Funkce custom_sum() vrati soucet dvou parametru a, b nebo 0, pokud je soucet zaporny. # Parametry a, b jsou cela nebo realna cisla. # # Function custom_sum returns sum of two parameters a, b or 0, when the sum is negative. # Parameters a,b are integer or real numbers. # # custom_sum(5, 10) => 15 # custom_sum(-5, 2) => 0 # # 1 bod # 1 point def custom_sum(a, b): return 0 # Funkce min_abs() vrati ze zadaneho listu nejmensi absolutni hodnotu. # # Function min_abs() return minimal absolute value from parameters list. # # [-5, -2, 3, 8] => 2 # [-10, 1+1j, 2] => 1.4142135623730951 # # 1 bod # 1 point def min_abs(list): return 0 # Funkce remove_unique odstrani ze zadaneho listu unikatni hodnoty a vrati novy list. # # Function remove_unique remove from list unique value and return this new list. # # [1, 1, 2, 3] => [1, 1] # [2, 3, 4, 3, 4, 8, 9, 0, 3, 9, 8] => [3, 4, 3, 4, 8, 9, 3, 9] # # 2 body # 2 points def remove_unique(list): return [] # Funkce weighted_mean pocita vazeny prumer ze zadaneho listu, tak ze prvni prvek je do prumeru zapocitan s vahou weight. # Pro list [1, 2, 3] a weight 2 to znamena, ze 1 je zapocitana dvakrat a pocet prvku je tedy 4. # # Function weighted_mean calculate weighted mean from list, that first item from list is weighted by parameter weight. # For list [1, 2, 3] and weight 2 it means, that 1 is counted two times and length of list is 4. # # [1, 2, 3], 2 => 1.75 # [2.3, 5.6, 1.2], 5 => 2.6142857142857143 # # 2 body # 2 points def weighted_mean(list, weight): return 0.0 # Funkce goto prejde na zadanou pozici position a prochazene prvky umisti na konec. # # Function goto passes to entered position and brosing value move to end of list. # # [1, 2, 3, 4, 5], 4 => [4, 5, 1, 2, 3] # ['A', 'B', 'Q', 'Z'], 3 => ['Q', 'Z', 'A', 'B'] # # 2 body # 2 points def goto(list, position): return [] # # Domaci ukol 05 # Homework 05 # # 8 bodu # 8 point # def is_dna_sequence(sequence): return True def reverse_complement_sequence(seqeunce): pass def reading_frames(sequence): # HINT: use function reverse_complement_sequence return ["AGTAGTAGT", "GTAGTAGT", "TAGTAGT", "ACTACTACT", "CTACTACT", "TACTACT"] def translate_codon(codon): codon_dictionaty = { 'ACT': 'T', 'AGT': 'S', 'CTA': 'L', 'GTA': 'V', 'TAC': 'Y', 'TAG': '-' } if codon_dictionaty.has_key(codon): return codon_dictionaty[codon] return "?" def translate(sequence): if not is_dna_sequence(sequence): return None protein_sequences = [] for frame in reading_frames(sequence): protein_sequence = "" i = 0 while i+3 <= len(frame): codon = frame[i:i+3].upper() protein_sequence += translate_codon(codon) i += 3 protein_sequences.append(protein_sequence) return protein_sequences ### KONEC ### END # Neupravujte nasledujici kod. Don't update following code. correct = 0 wrong = 0 print("Testing functions:") print("-"*40) if show_case() : print("{:37} {}".format("Function #0 (show_case):", "ok *")) else: print("{:37} {}".format("Function #0 (show_case):", "ko -")) if custom_sum(10, 5) == 15 and custom_sum(-5, 2) == 0: print("{:37} {}".format("Function #1 (custom_sum):", "ok *")) correct += 1 else: print("{:37} {}".format("Function #1 (custom_sum):", "ko -")) wrong += 1 if min_abs([-5, -2, 3, 8]) == 2 and min_abs([-10, 1+1j, 2]) == 1.4142135623730951: print("{:37} {}".format("Function #2 (min_abs):", "ok *")) correct += 1 else: print("{:37} {}".format("Function #2 (min_abs):", "ko -")) wrong += 1 if remove_unique([1, 1, 2, 3]) == [1, 1] and remove_unique([2, 3, 4, 3, 4, 8, 9, 0, 3, 9, 8]) == [3, 4, 3, 4, 8, 9, 3, 9, 8]: print("{:37} {}".format("Function #3 (remove_unique):", "ok *")) correct += 1 else: print("{:37} {}".format("Function #3 (remove_unique):", "ko -")) wrong += 1 if weighted_mean([1, 2, 3], 2) == 1.75 and weighted_mean([2.3, 5.6, 1.2], 5) == 2.6142857142857143: print("{:37} {}".format("Function #4 (weighted_mean):", "ok *")) correct += 1 else: print("{:37} {}".format("Function #4 (weighted_mean):", "ko -")) wrong += 1 if goto([1, 2, 3, 4, 5], 4) == [4, 5, 1, 2, 3] and goto(['A', 'B', 'Q', 'Z'], 3) == ['Q', 'Z', 'A', 'B']: print("{:37} {}".format("Function #5 (goto):", "ok *")) correct += 1 else: print("{:37} {}".format("Function #5 (goto):", "ko -")) wrong += 1 seq1 = 'agtagtagt' result1 = translate(seq1) if result1 == ['SSS', 'VV', '--', 'TTT', 'LL', 'YY']: print("{:37} {}".format("Function #6 (translate) test 1:", "ok *")) correct += 1 else: print("{:37} {}".format("Function #6 (translate) test 1:", "ko -")) wrong += 1 seq2 = 'GACGCAGTGGATCCGTACAATAG' result2 = translate(seq2) if result2 == ['DAVDPYN', 'TQWIRTI', 'RSGSVQ-', 'LLYGSTA', 'YCTDPLR', 'IVRIHCV']: print("{:37} {}".format("Function #6 (translate) test 2:", "ok *")) correct += 1 else: print("{:37} {}".format("Function #6 (translate) test 2:", "ko -")) wrong += 1 print("-"*40) print(seq1) print(result1) print(seq2) print(result2) print("-"*40) print("Spravne/correct: {}".format(correct)) print("Spatne/wrong: {}".format(wrong))