Skip to content

Instantly share code, notes, and snippets.

@andriiburka
Created March 18, 2020 13:32
Show Gist options
  • Save andriiburka/7be08a830cbbc73a13340ffa1b3c2d93 to your computer and use it in GitHub Desktop.
Save andriiburka/7be08a830cbbc73a13340ffa1b3c2d93 to your computer and use it in GitHub Desktop.
text = input().replace(" ", "").split()
alphabet = {chr(i): i - 96 for i in range(ord('a'), ord('z') + 1)}
total = []
for word_index in range(len(text)): # for word in text
tup = int(text[word_index][1:-1]), text[word_index][0], text[word_index][-1]
current = 0
for char in range(1, len(tup)):
if char == 1:
if tup[char].isupper(): # ДЕЛИМ
first_lower = tup[char].lower()
for upper_first_letter, place in alphabet.items():
if upper_first_letter == first_lower:
current += (tup[0] / place)
break
elif tup[char].islower(): # УМНОЖАВАМЕ
for lower_first_letter, place in alphabet.items():
if lower_first_letter == tup[1]:
current += (tup[0] * place)
break
elif char == 2:
if tup[char].isupper(): # МАХАМЕ от CURRENT
second_lower = tup[char].lower()
for upper_second_letter, place in alphabet.items():
if upper_second_letter == second_lower:
current -= place
break
elif tup[char].islower(): # ДОБАВЯМЕ към CURRENT
second_word = tup[char]
for lower_second_letter, place in alphabet.items():
if lower_second_letter == second_word:
current += place
break
total.append(current)
print(f'{sum(total):.2f}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment