Home python Task on PY.Checkio on Python 3

Task on PY.Checkio on Python 3




Good afternoon, I sit on Py.Checkio, studying Python 3. Now the task of which you need to replace all the words Right on Left. I decided to go probably difficult way and decided to go through a lot of cycles. In short, here is my code:

def left_join (Phrases: Tuple) - & gt; Str:
  result_str = ''
  For CH in Phrases:
    res_ch = str (CH) .split ('')
    Length = Len (RES_CH)
    For Char in Res_ch:
      IF 'Right' In Str (Char):
        START = STR (CHAR) .Find ('Right')
        END = START + LEN ('RIGHT')
        Result = Str (char) [: start] + 'left' + str (char) [end:]
        If Length & GT; 1:
          result_str + = result + ''
          Length - = 1
          IF LEN (Phrases) == 1:
            result_str + = result
            result_str + = result + ','
        IF char == phrases [-1]:
          result_str + = str (char)
          result_str + = str (char) + ','

Problem start when it is trying to automatically substitute a tuple (“Lorem”, “Ipsum”, “Dolor”, “Sit”, “Amet”, “Consectetuer”, “Adipisting”, “ELIT”, “Aenean”, ” Commodo “,” Ligula “,” Eget “,” Dolor “,” Aenean “,” Massa “,” Cum “,” Sociis “,” Natoque “,” Penatibus “,” et “,” magnis “,” dis ” , “Parturient”, “Montes”, “Nascetur”, “ridiculus”, “mus”, “donec”, “quam”, “felis”, “ultricies”, “nec”, “petelntesque”, “eu”, ” Pretium “,” Quis “,” SEM “,” Nulla “,” Consequat “,” Massa “,” quis “).

He gives the words




For some reason, as one whole, that is, ‘Quissem’.

I do not understand why, I tried to look at the visualizers and in different IDLE, I do not understand why he glues exactly these lines

Answer 1, Authority 100%

if char == phrases [-1]: # with char == "QUIS"
  result_str + = str (char) # elements glued
  result_str + = str (char) + ',' # otherwise separated by a comma

Here is your gluing, because the last element of the taper, i.e. phrases [-1] you have "quis" and therefore on the "quis" element which is SEM in front of the This if is executed and the elements are not separated by the comma, unlike all other passes of the cycle on the elements of the price.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions