DiYane

Messaging

Aug 9th, 2023
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def calculate_digit_sum(number):
  2.     return sum(int(digit) for digit in str(number))
  3.  
  4.  
  5. def main():
  6.     sequence = input().split()
  7.     text = input().strip()
  8.  
  9.     message = []
  10.  
  11.     for num in sequence:
  12.         index = calculate_digit_sum(num)
  13.         if index > len(text):
  14.             index %= len(text)
  15.  
  16.         char = text[index]
  17.         message.append(char)
  18.         text = text[:index] + text[index + 1:]
  19.  
  20.     result = ''.join(message)
  21.     print(result)
  22.  
  23.  
  24. if __name__ == "__main__":
  25.     main()
  26.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment