I was thinking the exact same thing.
I’m not sure what the purpose of using length while slicing.
I guess just to know multiple ways to skin a cat??
No idea.
the instructions want you to learn and use the len() function to get the number of characters in the string and then subtract a number from that to give it the index of where to start the slice.
it is a little silly in the use of this exercise because you can just use string_name[-3:] to get the last 3 characters of the string (as many have already mentioned)
but suppose you need to cut the string in half no matter how many characters you’re give, in that case you would want to know how to use len() and then divide by 2, etc. really this exercise is just like anything else in school, the more you use something, even if its overkill, the more you’ll actually learn it and remember it.
I had this question in functions earlier and I thought it would eventually snap, but it hasn’t. I’m missing these exercises on the same issue, assigning the function to a variable outside of the function. The password_generator creates the temp_password variable. Why must the temp_password be defined again with the call of the function instead of calling the function?
This produces the expected result:
temp_password = password_generator(first_name, last_name)
print(temp_password)
This prints the location of the function but this is what I expected to work:
password_generator(first_name, last_name)
print(password_generator)
The first example gives the return value of the function somewhere to go. The second example calls the function but does not assign the return value. In the last print statement, password_generator is not the name of a variable, but a reference to the function.
Yep, same thing here.
I imagine they want us to know that we can have an index to work with. Say for example you needed to extract the middle part of the list. But then an exercise where we have to do that would show a better example on why that is necessary.
Nah, I rather ask why EVERY time I feel like it, that’s part of learning and should never be discouraged. I’m actually surprised you are doing it being a moderator.
BTW, the ‘why’ in this case is explained in the very next lesson, is is to show you that there is a hard way and an easy way. For anyone else wondering the same question.
Reinforcing the need to follow lessons, complete the exercises and move on. The why questions can come up during a unit review, if any still exist. If we populate all the narrative with reasons why it will pollute the rudimentary learning process with information overload. Rote first, muscle memory and rudimentary understanding of syntax and basic usage is far more important than the reasoning behind it, at that stage. Most times the why of things reveals itself in due course of time once the learner has had some practice and developed a broader view of the landscape.
This exercise is broken. I write a code that returns the correct answer and the exercise says it returns nothing. My code works in VS code. I can’t pass this exercise due to the fact that even hitting “replace” on what is the “correct” (aka your code is exactly like ours) answer. If I could go back I would NOT pay for pro.
Out of curiosity, can you share your code? At the bottom of the exercise, there should be a “Copy to Clipboard” button.
Posting directly into the forums will mess up the formatting and indentation.To paste the code in the forums with proper formatting, see: How do I format code in my posts?
Alternatively, you can upload a screenshot.
Also, what does the feedback/error message that pops up at the bottom say?