Advertisement
SimeonTs

SUPyF2 Text-Pr.-Ex. - 02. Character Multiplier

Oct 27th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#1
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 02. Character Multiplier
  6.  
  7. Problem:
  8. Create a method that takes two strings as arguments and returns the sum of their character codes multiplied
  9. (multiply str1[0] with str2[0] and add to the total sum). Then continue with the next two characters.
  10. If one of the strings is longer than the other,
  11. add the remaining character codes to the total sum without multiplication.
  12.  
  13. Examples
  14. Input           Output
  15. Gosho Pesho     53253
  16. 123 522         7647
  17. a aaaa          9700
  18. """
  19. one, two = input().split()
  20. total = 0
  21. for i in range(max(len(one), len(two))):
  22.     try:
  23.         if one[i] and two[i]:
  24.             total += (ord(one[i]) * ord(two[i]))
  25.     except Exception:
  26.         try:
  27.             if one[i]:
  28.                 total += ord(one[i])
  29.         except Exception:
  30.             try:
  31.                 if two[i]:
  32.                     total += ord(two[i])
  33.             except Exception:
  34.                 continue
  35. print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement