Advertisement
GeorgiLukanov87

08. Letters Change Numbers Text Processing - Exercise 100/100

Jul 22nd, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. # 08. Letters Change Numbers Text Processing - Exercise 100/100
  2. # https://judge.softuni.org/Contests/Compete/Index/1740#7
  3.  
  4. def char_position(some_letter):
  5.     return ord(some_letter.lower()) - 96
  6.  
  7.  
  8. data = input().split()
  9. final_sum = []
  10.  
  11. for all_letters in data:
  12.     number = ""
  13.     non_digits = ""
  14.     for char in all_letters:
  15.         if not char.isalpha():
  16.             number += char
  17.         else:
  18.             non_digits += char
  19.            
  20.     all_letters = all_letters.replace(number, "")
  21.     total_sum = 0
  22.     first_letter = all_letters[0]
  23.     last_letter = all_letters[-1]
  24.    
  25.     if first_letter.islower():
  26.         total_sum += float(number) * char_position(first_letter)
  27.     elif first_letter.isupper():
  28.         total_sum += float(number) / char_position(first_letter)
  29.        
  30.     if last_letter.islower():
  31.         total_sum += char_position(last_letter)
  32.     elif last_letter.isupper():
  33.         total_sum -= char_position(last_letter)
  34.     final_sum.append(total_sum)
  35.  
  36. if len(data):
  37.     print(f"{sum(final_sum):.2f}")
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement