Honestly, I felt like you at this point. I then returned back to the explanation unit!
I just gotta add something since I’ve been reading many people complaining about how Codecademy lessons never covered sum() or max() functions and so on. So I’ll try and make my reply here as short as I can, but informative and encouraging for anyone who never had experience coding, just like me
If you feel like the lessons haven’t covered Python functions, you haven’t been paying attention! There’s a reason why every lesson has a link to Codecademy forums at the bottom. And after finishing a lesson I’ve NEVER moved on to the next lesson without checking the linked subject on the forum first. I read through everything and take notes. Don’t skip and don’t try to make this journey easier.
And ■■■■ yeah, the challenges are not easy for begginers. But again, they are called “challenge” for a reason, don’t you think? And they certainly live up to their name… on some of these I’ve spent days. Until I’ve run out of every possible combination my brain could think of, until I’ve completely run out of will and motivation to keep solving the problem, only then I’d check the solution. It happened three times so far. BUT I would never just leave after that. I would write down the entire problem so I can always return to it cause my brain will probably slip on a similar problem again in future and then I would study the code line by line until I’m 100% sure I understand every piece of it and what I was doing wrong.
Be resourceful just like you would in school or college, check everything Codecademy offers, google if need be but be sure to understand the process and what every piece of code does. It’s perfectly ok to be stuck on a problem and it’s ok to fail sometimes. As long as you learn from all of it, it can only benefit you.
Cheers Everyone and good luck
The main issue I have had with the exercises would seem to be more of a bug. My solutions return what the exercise is asking; however, I then get error messages saying I supposedly do not have the correct answer when the console is showing I do. I do have a lot of prior experience with software development. Though a majority of my experience to this point has be with C#, VB .NET, Java, T-SQL, MySQL, and a few other things I learned during my associates and then bachelor’s degree programs.
Keep up the work. learning to code can take time; if you ever seem overwhelmed, the best thing to do is just get up and walk away for a bit. Also, creating pseudo-code which someone has referenced would help. Also, Google is always a great place to go for answers.
Ian, if you kept with it, I hope Python got a bit easier to understand
I was thinking in the order, first validating if the list is empty or not, then the first statement validating if its less than 9000, and last the break to stop the loop
#Write your function here def over_nine_thousand(lst): sum = 0 if len(lst) == 0: return 0 for i in lst: sum += i if sum < 9000: print("this is lower") elif sum > 9000: break return sum #Uncomment the line below when your function is done print(over_nine_thousand([8000, 900])) # change the values for testing
I feel the same most of the time. Just knowing that I still have few more code challenges to go made me don’t want to show up in Codecademy, and I dread those challenges even more each day. The solutions and other people’s code really made sense when I see them, but I cannot articulate the solution using Python from scratch. It feels like I know it should go like that, but I don’t know how to translate it into codes, Sometimes I passed the challenges, but not in the way they want me to do it (use loops, etc.).
In my unfortunate days, the cycle usually goes like this: tried to code without using hint, then got an error. I looked at the hint, it made me way more confused, tried to follow it anyway and still got an error. I always opened the forum, then got lost in the posts, tried few solutions that made sense to me, which usually works. If everything in the forum does not make any sense to me at all, I finally hit that View Solution button, which is often. Next, I embrace all the sadness, frustrated, demotivated and defeated feelings while taking notes of the solutions (I put them inside a private repo in my GitHub account, just to get myself used to GitHub) and go back to the lessons and find other resources to make sure I understand it. For now, it is clear that I need more exercises on lists and loops.
Even so, here I am keep going through all the lessons and challenges. It’s definitely not easy, but I think it’s worth it. I’m sure there are many people who feel discouraged but decided to keep going, and it’s a good thing to do.
Code someone review my code and tell me whether I did it correctly or if I missed the mark? Either way it seems to satisfy all three cases, and I am allowed to progress. I guess I’m surprised because it just seems so simple.
#Write your function here def over_nine_thousand(lst): sum1 = 0 for num in lst: if sum1 < 9000: sum1 += num return sum1 #Uncomment the line below when your function is done print(over_nine_thousand()) #print(over_nine_thousand([8000, 900, 120, 5000]))
over != at least
try to match your code semantically to what the requirement is. it should do that
so if it says over, then you really need to test “is it more than 9000? if so, stop”, you’re doing something slightly different, it doesn’t semantically match
and it says “stop”, but your loop will continue, so that doesn’t match
Ok, so what is the question asking me, because it is a bit obtuse? From what I understood, and from the desired result of the provided code, it seems that you just keep adding the next element in the list until the sum is over 9000.
Is it that I am supposed to check all the elements, and determine which elements I can add until it hits 9000?
Argh I’m just even more confused, especially since I am allowed to progress with the code I created.
your code does not do that.
wildly inadequate tests
you are doing things that are similar. a human might say it’s close enough.
but it’s different
it doesn’t do the thing promised
so your options are to either ensure it is equivalent (harder)
or do the thing the function description says (easier)
If the description says over 9000, then you’d want to test for over 9000, not less than 9000. Yeah there’s something equivalent you can do there, but now you’ve created a new problem, you have to ensure it’s equivalent. If you test for the same thing, that’s one problem less, therefore that is easier to get right.
The stopping mechanic is also something where you do something that might be made equivalent, but it continues to do things after the condition result has changed, is that equivalent? If you brought it to a stop, you’d be doing the same thing as the description says and you wouldn’t need to worry about whether it’s equivalent.
I second the pythontutor.com suggestion as a way to find clues. It is a little frustrating and I am pretty sure some techniques were not taught in lessons, despite other postings to the contrary. Maybe I should be checking every link in every lesson, but not all are relevant and they take time to review.
I find these challenges daunting at times because I am learning what I don’t know, but checking forum posts on challenges and googling and trying code in python tutor are part of the learning process, I guess.
Yeah but I can find Python forum on Reddit or other sites, without paying almost 10% of my salary for it. Codecademy as it is right now is just not for me.
Maybe I’ll come back when I’m ready for machine learning course but now I feel like it’s teaching me syntax but not what to do with it which is so frustrating that every once in a while I need some coding motivational video just to keep me wanting to learn code.
How do you use pythontutor? Whatever I paste in code editor I get just one step which doesn’t seem right. It just shows me that I am defining a function and that’s it, no way to see how it executes the code.
I would experiment with it a bit. Put a solution that codecademy gives and see what it does with that for example. I have had it give me just a single step when I put in several lines of code. Putting the return in a function at wrong indent level may have been the cause. It doesn’t always give me clues, but I think it is a good tool for learning.
After if condition you write an else condition to return the sum, because your code is valid for the below conditions
- If sum is greater than 9000
- If list is empty
You did not write code for the the condition what should be return if sum is less than 9000
You can change the code as follows
def over_nine_thousand(lst): sum = 0 for num in lst: sum += num if sum > 9000: return sum break else: return sum
If the list is empty, it will return sum as zero.
hey. i tried your code, and it didn’t work for me. what am i doing wrong?
this is my code:
def over_nine_thousand(lst): lst_sum = 0 for i in lst: lst_sum += i if lst_sum > 9000: return lst_sum break else: return lst_sum
never mind. i figured it out. thanks.
You right @levyrigor!! I can’t click NEXT until i read all community forum questions below the instructions!! They are very helpful, for exemple, in this one i just got familiar with the “Visualize your code” web app and “Automate boring stuff with Python” book! I also save some comments to bookmarks…
…once i read… “If it doesn’t challenge you, it won’t change you!” Challenge is change, and change to better hopefully!
Just keep coding @refined_silver!!! and reading forums!!
Me the same,when you think like this, I think it’s the good time to pause and take a look back. What I did is :
Return back to the lesson, take note in an easiest way so you can look easier when you need ( like : how to use, when to use…). As simple as possible.
Try again every single concept that you need help before. If you still can’t solve it without hint, that could be the the missing piece you need. Take a look in forum, try to understand it. Take a break, solve it again the next day and so on, as soon as you get familiar with it.
Trust me I always use my notebook when I solve the new concepts, just look through every lesson to see what I can use and try it. Later I get used to and look no more.
More important than anything: Don’t give up and Keep moving forward!
Hope it can help.
i solve it this way:
for ix in lst:
if suma > 9000: