|
| 1 | +# ###1 |
| 2 | +# if __name__ == '__main__': |
| 3 | +# # x = int(input()) |
| 4 | +# # y = int(input()) |
| 5 | +# # z = int(input()) |
| 6 | +# # n = int(input()) |
| 7 | +# |
| 8 | +# ## all cases |
| 9 | +# def all_cases(x=1, y=1, z=2) -> []: |
| 10 | +# all_cases = [] |
| 11 | +# |
| 12 | +# cases = [[i,j,k] for i in range(0,x+1) for j in range(0, y+1) for k in range(0,z+1)] |
| 13 | +# return cases |
| 14 | +# |
| 15 | +# |
| 16 | +# ## cases where it's not equal to n |
| 17 | +# |
| 18 | +# def equal_cases(cases, n=3): |
| 19 | +# equal_cases = [i for i in cases if i[1]+i[2]+i[0]==n] |
| 20 | +# |
| 21 | +# |
| 22 | +# return equal_cases |
| 23 | +# |
| 24 | +# |
| 25 | +# # print(equal_cases(all_cases(x, y, z), 3)) |
| 26 | +# print(equal_cases(all_cases())) |
| 27 | + |
| 28 | +#2 second lowest |
| 29 | + |
| 30 | + |
| 31 | +# students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]] |
| 32 | +# |
| 33 | +# |
| 34 | +# ### need to print second lowest, if there are 2 grades print them alphabetically |
| 35 | +# |
| 36 | +# highest = students[0][1] |
| 37 | +# runner = float('inf') |
| 38 | +# |
| 39 | +# for i in range(1, len(students)): |
| 40 | +# if students[i][1] < highest: |
| 41 | +# runner = highest |
| 42 | +# highest = students[i][1] |
| 43 | +# elif students[i][1] < runner and students[i][1] != highest: |
| 44 | +# runner = students[i][1] |
| 45 | +# |
| 46 | +# print(runner) |
| 47 | +# |
| 48 | +# selected = [i for i in range(0,len(students)) if students[i][1] == runner] |
| 49 | +# ready = [] |
| 50 | +# |
| 51 | +# for i in selected: |
| 52 | +# ready.append(students[i]) |
| 53 | +# |
| 54 | +# ready.sort() |
| 55 | +# |
| 56 | +# |
| 57 | +# |
| 58 | +# |
| 59 | + |
| 60 | +###3 |
| 61 | + |
| 62 | +string = 'Banana' |
| 63 | +vowels = ['a', 'e', 'i', 'o', 'u'] |
| 64 | +consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'] |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +def count_stuart(string): |
| 69 | + words = [] |
| 70 | + |
| 71 | + for po1 in range(len(string)): |
| 72 | + if string[po1].lower() in consonants: |
| 73 | + for po2 in range(po1 + 1, len(string)+ 1): |
| 74 | + words.append(string[po1:po2]) |
| 75 | + |
| 76 | + score_dict = {word : words.count(word) for word in words} |
| 77 | + total_points = 0 |
| 78 | + |
| 79 | + for k,v in score_dict.items(): |
| 80 | + total_points += v |
| 81 | + |
| 82 | + return total_points |
| 83 | + |
| 84 | +def count_kevin(string): |
| 85 | + words = [] |
| 86 | + |
| 87 | + for po1 in range(len(string)): |
| 88 | + if string[po1].lower() in vowels: |
| 89 | + for po2 in range(po1 + 1, len(string) + 1): |
| 90 | + words.append(string[po1:po2]) |
| 91 | + |
| 92 | + score_dict = {word: words.count(word) for word in words} |
| 93 | + total_points = 0 |
| 94 | + |
| 95 | + for k, v in score_dict.items(): |
| 96 | + total_points += v |
| 97 | + |
| 98 | + return total_points |
| 99 | + |
| 100 | +def minion_game(string) -> str: |
| 101 | + kevin = count_kevin(string) |
| 102 | + stuart = count_stuart(string) |
| 103 | + result = '' |
| 104 | + if kevin > stuart: |
| 105 | + result = f'Kevin {kevin}' |
| 106 | + elif stuart > kevin: |
| 107 | + result = f'Stuart {stuart}' |
| 108 | + else: |
| 109 | + result = 'Draw' |
| 110 | + |
| 111 | + return result |
| 112 | + |
| 113 | + |
| 114 | +print(minion_game(string)) |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
0 commit comments