muhammad_nasif

TASK_14

Apr 16th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from math import ceil
  2.  
  3.  
  4. def sentenceChange(sentence, position):
  5.     newString = ""
  6.     tempString = ""
  7.     length = len(sentence)
  8.     if length == 1:
  9.         return sentence
  10.     else:
  11.         loopTimes = int(ceil(length / position))
  12.         newString = sentence[0]
  13.         start = 1
  14.         end = position
  15.         removeIndex = 0
  16.         for i in range(0, loopTimes):
  17.             if removeIndex !=0 and removeIndex < length:
  18.                 tempString += sentence[removeIndex]
  19.             newString += sentence[start:end]
  20.             start += position
  21.             end += position
  22.             removeIndex += position
  23.  
  24.     newString += tempString
  25.  
  26.     return newString
  27.  
  28.  
  29. sentence = input()
  30. position = int(input())
  31. print(sentenceChange(sentence, position))
  32.  
Add Comment
Please, Sign In to add comment