Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 08. Letters Change Numbers Text Processing - Exercise 100/100
- # https://judge.softuni.org/Contests/Compete/Index/1740#7
- def char_position(some_letter):
- return ord(some_letter.lower()) - 96
- data = input().split()
- final_sum = []
- for all_letters in data:
- number = ""
- non_digits = ""
- for char in all_letters:
- if not char.isalpha():
- number += char
- else:
- non_digits += char
- all_letters = all_letters.replace(number, "")
- total_sum = 0
- first_letter = all_letters[0]
- last_letter = all_letters[-1]
- if first_letter.islower():
- total_sum += float(number) * char_position(first_letter)
- elif first_letter.isupper():
- total_sum += float(number) / char_position(first_letter)
- if last_letter.islower():
- total_sum += char_position(last_letter)
- elif last_letter.isupper():
- total_sum -= char_position(last_letter)
- final_sum.append(total_sum)
- if len(data):
- print(f"{sum(final_sum):.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement