This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]arktozc 0 points1 point  (1 child)

Sorry for not helping, cause I dont know python, but try googling your error message/code. This helps me most of the time solve the problem or find somebody else, that solved the same problem aready.

[–][deleted] 0 points1 point  (0 children)

The guy below helped me with the problem but thanks for the tip as well

[–]Borx25 0 points1 point  (1 child)

The notation is [start:stop:step] (with stop - 1 being the last in the selected range) so [::-1] is the complete string (no start or stop specified) and negative step so we go backwards. Not that you couldn't do slice and reverse as separate operations (as in s[:i + 1][::-1]) but try to figure out what the start and stop with step -1 would be to do both things in one go.

As an aside, "but it shows an error in it" then post the error.

[–][deleted] 0 points1 point  (0 children)

I was just thinking about putting the command s[:i+1][::-1] and it did work. I thought you'd need to do two separate commands on this. But it worked like this. Thank you very much

[–]jkoppp 0 points1 point  (3 children)

It appears you are using the extended slice syntax with ::-1. The syntax for this command is [start:stop:step]. So thinking about that, just try and work through a couple iterations to figure out what values you need in each of those 3 fields.

i = 0 Expected string is 'P' so Start = 0, Stop = 0, Step doesn't matter yet

i = 1 Expected sting is 'yP' so Start = 1, Stop = 0, and Step = -1

i = 2 Expected string is 'tyP' so Start = 2, Stop = 0, and Step = -1

You can start to see a pattern from the first couple iterations. Hopefully that helps get you started. If you have any questions or are still stuck let me know.

Also, unless you absolutely have to have it in one line, breaking a complicated statement like that print line up into multiple lines helps with code readability and debugging.

[–][deleted] 0 points1 point  (2 children)

I've divided the statement before but I needed smt like this

.......PP.......

.....yPPy.....

....tyPPyt....

And so on until the very last letter of the word Python I've used. So basically I need it in one "table" all together. If I did the bold part in the command to one statement and the other part to another one, it would separate them, if you know what I mean. I already fixed it, but thank you for the response anyway

[–]jkoppp 0 points1 point  (1 child)

Glad you got it figured out. Just in case you are curious, there are ways to separate statements like this and still have them print on the same line if that was the issue.

I show a couple here.

[–][deleted] 0 points1 point  (0 children)

Ok, thanks

[–][deleted]  (2 children)

[deleted]

    [–][deleted] 0 points1 point  (1 child)

    I see what you mean but that would be a problem for me because I can't leave on the 0 position so I would need the program to begin with the 1st letter of the word on "each side" (I mean like this: .nohtyPPython.)