card1, card2 = [[card[:-1], card[-1]] for card in cards] suits = ['C', 'D', 'H', 'S'] values = ['6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] result = 'Error' value1 = values.index(card1[0]) value2 = values.index(card2[0]) suit1 = card1[1] suit2 = card2[1] if suit1 == suit2: if value1 > value2: result = 'First' elif value2 > value1: result = 'Second' elif suit1 == trump_suit: result = 'First' elif suit2 == trump_suit: result = 'Second' helper.write_stdout(result) # Sample Input 1: # AH JH # D # Sample Output 1: # First
import helper lines = helper.read_file('5.15_test.txt') fraction = lines[0].split('/') numerator = int(fraction[0]) denominator = int(fraction[1]) def simplified_form(numerator, denominator): floor_part = numerator // denominator coef_list = [floor_part] fraction_part = numerator % denominator if fraction_part > 0: coef_list = coef_list + simplified_form(denominator, fraction_part) return coef_list result = list(map(str, simplified_form(numerator, denominator))) # 239/30 # 7 1 29 helper.write_stdout(' '.join(result))
import helper import numpy as np # lines = helper.read_stdin() lines = helper.read_file('5.21_test.txt') shape = lines[0] rows = [list(line.split(' ')) for line in lines[1:]] matrix = np.array(rows) shape = shape.split(' ') assert len(shape) == 2, 'the argument shape must be equal to 2' shape = list(map(int, shape)) assert list( matrix.shape ) == shape, 'the argument shape is not the same as the actual shape' join_cols = map(lambda row: ' '.join(row) + '\n', matrix.T) join_rows = ''.join(list(join_cols)) helper.write_stdout(join_rows)
import helper lines = helper.read_file('5.4_test.txt') number_rome = lines[0] number_decimal_list = [] rome_to_decimal = { 'M': 1000, 'D': 500, 'C': 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1 } for char in number_rome: number_decimal_list.append(rome_to_decimal[char]) number_decimal = 0 for num1, num2 in zip(number_decimal_list, number_decimal_list[1:]): if num1 >= num2: number_decimal += num1 else: number_decimal -= num1 number_decimal += num2 helper.write_stdout(str(number_decimal))
{'from': 'km', 'to': 'm', 'factor': 1000}, {'from': 'cm', 'to': 'm', 'factor': 0.01}, {'from': 'mm', 'to': 'm', 'factor': 0.001}, ] conversion_to_meter = {'m': 1} def to_meter_base(): # first fill all direct conversions for item in conversion_list: if (item['from'] != 'm') and (item['to'] == 'm'): conversion_to_meter[item['from']] = item['factor'] # fill indirect conversions to meter for item in conversion_list: if (item['to'] != 'm') and (item['from'] not in conversion_to_meter): conversion_to_meter[item['from']] = item['factor'] * conversion_to_meter[item['to']] to_meter_base() # <number> <unit_from> in <unit_to> matches = re.search('([\de.]+)\s(\w{,5})\sin\s(\w{,5})[\s]*', lines[0]) if matches: number, unit_from, unit_to = matches.groups() number = float(number) number_m = number * conversion_to_meter[unit_from] number_to = number_m * (1. / conversion_to_meter[unit_to]) helper.write_stdout('{:.2E}'.format(number_to))
import helper import numpy as np lines = helper.read_file('5.9_test.txt') left, right = [int(num) for num in lines[0].split(' ')] sequence = np.array(range(left, right + 1)) test_sequence_3 = sequence % 3 test_sequence_5 = sequence % 5 test_sequence_15 = sequence % 15 sequence = sequence.astype(str) sequence[test_sequence_3 == 0] = 'Fizz' sequence[test_sequence_5 == 0] = 'Buzz' sequence[test_sequence_15 == 0] = 'FizzBuzz' helper.write_stdout('\n'.join(sequence)) # Sample Input: # # 8 16 # Sample Output: # # 8 # Fizz # Buzz # 11 # Fizz # 13 # 14 # FizzBuzz # 16