#๐ School workk
72 messages ยท Page 1 of 1 (latest)
@sweet beacon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
which part are you struggling with exactly?
Basiclly i just need to put them in order for example this one i completed
But the one im struggling with i jsut dont understand it at all
which part? do you understand what it's trying to do?
(also using reversed for a variable name is kinda meh, it's a built-in function)
like, what's the first thing you should define?
Im not even sure tbvh with you my teacher jsut assigned this work to me and i started the class 3 days ago
alright, well, let's try to figure this out together then
what do you think makes most sense to be defined first? so, you are supposed to do something with the variable word, so, where do you feel should its definition go, roughly at the beginning, somewhere in the middle or the end?
I Think the Beginning would make the most sense
alr, well, we can put it there for now then
alr, what about the next step
do you know how string indices work?
and do you understand what range(i, -1, -1) does roughly?
do you know how string concatenation works?
I dont know what any of that means i apoligize, I still have alot to learn
that's alright, so, if you want to access a particular character in a string you can index that string as such string[index] where index = 0 is the first character in the string
so, to reverse a string, you can start from the last character of the string which is the length of the string - 1 because since indexing starts from 0, the last index is one less than the length of the string, does that make sense? so, we start from the last index which is i = len(word) - 1, does that make sense?
then, we also want to create a new empty string that we will use as the starting point for the palindrome
so, now you create an empty string called reversed
the next part might be a bit tricky, but we need to iterate over the indices in the string starting from the last index, so range can take in 3 arguments, the start, the end and the step, the start is inclusive, i.e., that is the first value you'll get, the end is exclusive, i.e., the last value you get is end - step, and the step is by how much the value is incremented on every iteration, so, we need to start from the last index that we have previously defined and the end index needs to be -1 since -1 - (-1) = 0 which is the last value we need to get to, because we are going from the last index to the first one (which is 0)
so, then we just need to add to the reversed string the character from the original word that has the index we are currently iterating over.
then it's a simple if/else check to see if the word is indeed a palindrome, that should be pretty self-explanatory, you just check if word is a palindrome (i.e., the word matches the reversed word), then print that it's a palindrome, else print that it's not a palindrome
Alright i understand a little
Im pretty sure these last 3 are in the right spots
No need to move those right?
Maybe the reversed = reversed can stay too but im not 100% on that 1
yeah, those seem to be in the right place
now, when do you want to print that it's a palindrome? if the word equals the reversed word, right?
so if the word string equals the reversed string, you print that it's a palindrome
it's probably one of the most intuitive bits of code you have there in that sense
alright, so, obviously we want to start by defining the word, right? so, as you have previously stated, you can move that to the beginning
and only then can you define i, because as you can see, it requires word to already be defined
and after that, you are ready to create the reversed string, so you start by making it an empty string and then in the for loop, you add the reverse indexed characters to it
and then check if it's a palindrome or not
alright, you need to define what reversed is before you can use it, right? does that make sense?
and you check that reversed is the same as word right before printing that it's a palindrome, right, does that make sense too?
Uhmm
I undrstand the defining it
but the second part doesnt make to much sense to me sorry
The defining reversed is this 1
Im prettty sure that circled one is the defining
So i would want to put that 1 right above the first dad command so that everythint else can be used?
alr, you need to check if the word equals the reversed word right before you print that it is indeed a palindrome
yea dad reversed is dad
yes, that's correct, but if it is inside the for loop, you will be creating it on every iteration/cycle, however that means you will end up with reversed being just the first letter of the word, you need to create it before the loop
right, but where do you think reversed = reversed + word[x] goes?
It should swap with if word ==reversed?
I dont think that command can work if reversed = reversed isint above it
Or mayne the reversed =reversed goes where the reversed ="" is cause its defining reversed as dad
can you try following this logic again and see if it maybe makes more sense now?
yeah, a lot
so, again, you want to add the reversed letter from word to reversed on every iteration and after that, once you have created your reversed word, that is when you compare it to the original word
solution ||swap if word ... with reversed = reversed + ...||
you're welcome
Idk why this one was so much harder then the others
mmm, well, considering you started learning this 3 days ago...
Thank you for your patiance, cause i know im not easy to deal with
nah, you were just fine
(also I just happened to be in the mood for this ๐)
anyway, you can now !close the post if this is solved
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.