Advertisement
horozov86

Letters Change Numbers

Mar 20th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from string import ascii_uppercase
  2. strings = input().split()
  3.  
  4. total_result = 0
  5. for sub_string in strings:
  6.     first_letter = sub_string[0]
  7.     last_letter = sub_string[-1]
  8.     number = int(sub_string[1:len(sub_string) - 1])
  9.  
  10.     first_letter_alphabet_position = ascii_uppercase.index(first_letter.upper()) + 1
  11.     if first_letter.isupper():
  12.         number /= first_letter_alphabet_position
  13.     else:
  14.         number *= first_letter_alphabet_position
  15.  
  16.     last_letter_alphabet_position = ascii_uppercase.index(last_letter.upper()) + 1
  17.     if last_letter.isupper():
  18.         number -= last_letter_alphabet_position
  19.     else:
  20.         number += last_letter_alphabet_position
  21.  
  22.     total_result += number
  23.  
  24. print(f"{total_result:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement