I'm struggling to understand this exercise?

I notice my knowledge in this is vastly dwindling due to how the instructions is describing what it wants me to do. Furthermore, I am using more hints and conclusions than I care to admit which means I am not learning much. The critical thing next is likely going to cause me to have a stroke. Is there any information out there that can be of better help to understand so I can come back and continue this?

4 Likes

I am having this same challenge.

2 Likes

Hi Guys

Just completed this exercise and had question regarding my code

single_digits = range(0,10)

for digits in single_digits:
squares =
for digits in single_digits:
squares.append(digits**2)
print(digits)

print(squares)

cubes = [digits ** 3 for digits in single_digits]

print(cubes)

Seems like I had to start another for loop in order to get the correct list squared (otherwise I just return 81 - if second for statemtent is ##)

New to all of this and cant quite see why this is the case.

Help greatly appreciated

Have the same question as yours… also curious why it’s returning the squared value of the last number.

It seems we are all in the same both, sometimes I feel so upset that I wanna break my laptop whenever is read the instructions, so confusing :confused:

Can anyone please help us @mtf where are you? You are my knight in shining armour here on Codecademy, you wanna save us, please?

1 Like

Let’s have a look at your code to see where the problem is arising.

For step one we can either manually build the list,

single_digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

or assign a range,

single_digits = range(10)

The second step asks us to print each item in the list using a loop:

for x in single_digits:
    print(x)

The third step asks for an empty list…

squares = []

Write that line above the loop, then move on to step 4.

for x in single_digits:
    print(x)
    squares.append(x ** 2)

Next we will print the squares list.

print(squares)

Step 6 assumes we know how to create a comprehension…

cubes = [x ** 3 for x in single_digits]

and finally, print that list…

print(cubes)
2 Likes

Hi Roy,

Thanks for your explanation. This is exactly how I wrote the code, but it didn’t woek. When I checked the solution, I found out that the empty square list was printed first whish is not the way the instruction was constructed.

I have to write it the way it was written in the solution before it worked. Mos of the few obstacles I have had with Codecademy tasks and quizzes are the way the instructions /questions are been made.

Thanks Roy for your usual help here

2 Likes

I had a bit of fun with this one:

single_digits = list(range(0,10))
print(single_digits)


squares=[]
cubes=[]
for i in single_digits:
  squares.append(i**2)
  print("the square of "  + str(i) + " is " + str(squares[-1]))
  cubes.append(i**3)
  print("the cube  of " + str(i) + " is " + str(cubes[-1]))

sample output

the square of 6 is 36
the cube of 6 is 216
the square of 7 is 49
the cube of 7 is 343

Enjoy!

2 Likes

Couple of things…

  1. If we only wish to iterate and not access elements in a range it does not need to be cast as a list.

  2. 0 is the default start value so we don’t need to write it. Mind we don’t need to see what 0**2 and 0**3 are, so we can start with 1, or even 2.

    for i in range(2,10):

  3. String formatting makes our code more readable and less wieldly.

    print ("The square of {x} is {y}".format(x=i, y=squares[-1]))

3 Likes

Thanks for the tip/follow through!

1 Like

…Starting from Loops, whole course is very poorly written.
Python 3 course at CA have issues in previous lessons too, but starting from chapter 5 it turns to playing games and trics with student’s mind.
Additionally, they don’t use PyCharm as workframe for their outside lessons what is frustrating.

Loops are one of the simplest topics (because it’s standard for / while / break / continue conditions), but not here.

As example, in 5.1.11 if fact they ask student to do range(10), but by request description it want to make xxx = [1, 2, …10].
And etc.

Same goes with me. Initially, the learning curve was going good at codecademy.

This is insane. I was doing SO well with codecademy and going to pay for the year after my trial was up. Been spending 2-4 hours a night digesting this stuff, starting from never coding or knowing anything about code. Once I hit lists, things became a little confusing… but I studied… and figured some things out on my own. But now? CC is throwing in a bunch of things and just expecting me to know how to use them? I was NEVER going to come up with “+=” ! WTF is that? How do I use the .pop() function? What variable does it attach to? What does it actually do? There’s no context whatsoever. They’ve been so good about explaining every little thing and suddenly it’s like I entered a completely new program. I was going to plunk down close to $300 tonight and now I’m considering just going somewhere else completely. I’m re-reading text over and over thinking it’s me and my comprehension levels, but I’m discovering that it is most certainly not. This is a real failure on the part of the CC team.

It appears as if the first 15% of the course was designed meticulously to get your financial commitment after the trial, and the rest was sloppily put together. I’m not sure that I’m going to continue – and I WANT to continue desperately because I’ve enjoyed the platform and it’s working really well for me – but forcing concepts and topics without properly introducing them is unforgivable. Is it just me?

Spend the money. You have a full year to capitalize on it. This becomes your court and there is time enough to sort out warts and all and still walk away with a complete experience. Careers have been launched from this site by many an apt pupil who didn’t walk away, despite the shortcomings. They more than made up for that by staying their course. Are you a quitter?

Oh, I feel you so much. I was so proud of my progress, really unterstood it, solved the challenges before on my own. But when Loops were introduced I didn’t get anything. The += operator wasn’t explained anywhere before, neither was .pop(). Maybe they want you to look it up and understand it yourself, and it did kinda work. But I felt bad for using the hints and was just typing it off. Read it a few times, tried to understand what’s happening. Did you do the project afterwards? Steps 1 - 12 I was like: Ok, maybe I got it? But Step 13:

Carly thinks she can bring in more customers by advertising all of the haircuts she has that are under 30 dollars.
Use a list comprehension to create a list called cuts_under_30 that has the entry hairstyles[i] for each i for which new_prices[i] is less than 30 .
You can use range() in your list comprehension to make i go from 0 to len(new_prices) - 1 .

No matter how hard I thought about it, I didn’t get it. Used the hint, typed it off, got it working but still not understanding why it did. Yeah, I don’t want to quit, but I guess what the people complaining here are trying to say is: The loops lessons aren’t very good compared to the lessons before! There’s such a big difference in speed of explaining what’s actually going on that people that were really motivated and willing to spend money suddenly think twice about it. Maybe rework that lesson somehow and introduce some elements earlier that are used here.

1 Like

Any advice then how to get this loops section into my head? Don’t wanna continue with something new until I really understood it, maybe there are some more exercises I could try? Just finished the first project of this lesson needing to use two hints because I was really stuck.

Please post a link to the exercise page so we can see where you’re at.

https://www.codecademy.com/courses/learn-python-3/projects/carlys-clippers

This was the exercise I did yesterday and how far I came so far. Came through it but don’t feel like I really understood it. Should I just continue because it will get clearer later or really stay at this topic until I fully unterstand? :slight_smile:

Keep reviewing and repeat anything that is still giving you trouble. Don’t hurry ahead with the idea that it will all become clear. We need to cement our understanding so we’re not walking in a fog.

Thanks for your help! Ok, will try all the loop challenges and maybe even lessons again and then look for some more challenges until I feel confident enough to move on. :slight_smile:

1 Like