#๐Ÿ”’ School workk

72 messages ยท Page 1 of 1 (latest)

sweet beacon
#

I just need quick help with this last question maybe someone here can help its due at 12 so Yeaaa tryna get it done.

snow falconBOT
#

@sweet beacon

Python help channel opened

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.

sweet beacon
#

I jsut need help with this last question for a project/homework due at 12

agile basin
#

which part are you struggling with exactly?

sweet beacon
#

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

agile basin
#

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)

agile basin
sweet beacon
#

Im not even sure tbvh with you my teacher jsut assigned this work to me and i started the class 3 days ago

agile basin
#

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?

sweet beacon
#

I Think the Beginning would make the most sense

agile basin
#

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?

sweet beacon
#

I dont know what any of that means i apoligize, I still have alot to learn

agile basin
#

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

sweet beacon
#

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

agile basin
#

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

sweet beacon
#

Okay you are right

#

I think this is a little better

agile basin
#

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?

sweet beacon
#

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?

agile basin
sweet beacon
#

yea dad reversed is dad

agile basin
agile basin
sweet beacon
#

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

agile basin
sweet beacon
#

I re read it and i think i understood it a bit more

#

does this look any better?

agile basin
#

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 + ...||

sweet beacon
#

Omg

#

Thank you so much

agile basin
#

you're welcome

sweet beacon
#

Idk why this one was so much harder then the others

agile basin
#

mmm, well, considering you started learning this 3 days ago...

sweet beacon
#

Thank you for your patiance, cause i know im not easy to deal with

agile basin
#

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

sweet beacon
#

Thank youuu

#

!close

snow falconBOT
#
Python help channel closed

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.