Timeline for Pset 3: Grocery list, the program ends after one item is inputted
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 28 at 21:42 | comment | added | UpAndAdam | Then you have missed something in the videos and slides. | |
Mar 28 at 20:25 | comment | added | Elvino Michel | I do not have an understanding of variable scope at all. | |
Mar 28 at 18:56 | comment | added | UpAndAdam | you pass variables into a function if you need the function to have access to them. sometimes a function doesnt need variables passed to it because of globals ( which are BAD ) or because it doesnt take any input. But thats a FAR BETTER QUESTION to ask then most of what you have asked. if you ask a specific question we can answer it for you. Do you have any concept of the understanding of what variable scope is? this should have been covered in lectures | |
Mar 28 at 14:40 | comment | added | Elvino Michel | Many thanks for the many comments and added explantions. I added a new solution, with I guess "too many" functions in this case... | |
Mar 28 at 14:36 | comment | added | Elvino Michel |
OK. Yes I do struggle a lot with functions. I do not get why sometimes a function is for example: def example() and sometimes def example(a, b) . Honestly this breaks my head I guess I am stupid.
|
|
Mar 28 at 14:25 | comment | added | UpAndAdam |
in the solution i describe you'd have really only two functions ( I don't count main ) you'd have an update_grocery_list function and possibly a print_grocery_cost function. or you could do the printing in main. do you need functions here technically no, but i think it will be helpful for you since you seem to struggle with functions and will make it more testable and give you smaller chunks to check for errors in. Computer Science and programming is the science/art of turning a problem into a collection of subproblems and by solving all the subproblems you solve the big problem
|
|
Mar 28 at 14:22 | comment | added | UpAndAdam | The reason for doing it in a function is modularity.. Say you do part 1 as i described, if you kept the logic i specified in a function, than during the next phase you are MOSTLY only changing the code in your function and not the code calling the function ( aside perhaps from the data type you pass into it). Also it means that instead of just calling main, you can make a test program that simply imports your file and calls your functions with hardcoded inputs to test that it behaves as expected. much easier to debug. | |
Mar 28 at 14:20 | comment | added | UpAndAdam | You break programs down into functions to make things more manageable, more readable, more testable, and for deduplication, reusability, and simplicity. If you struggle with functions you need to go back to rework the earlier lessons in this course and watch all the videos. go back to pset0 tip calculator, that shows a way to get use return values from functions by passing in variables. Functions allow you to change the value of things passed in or to change the value of globals or class members if its a class method as opposed to a raw function. | |
Mar 28 at 13:37 | comment | added | Elvino Michel | "Up to you for now what type cart is. the important part is you do that all in a function." ==> Why is it always important to use functions? | |
Mar 28 at 13:20 | comment | added | Elvino Michel | OK, I will try to do that. But almost seems then like I would have three functions. As for the other problem, I struggle with functions. I wonder how a function can give another result to another function. Additionally, I wonder how and if I can call variables in the same way across variable function (and if I do so, is this confusing the functions)? I would almost be glad to pay you and have session where I describe on a screen sharing my issue. | |
Mar 28 at 0:53 | history | edited | UpAndAdam | CC BY-SA 4.0 |
added 1654 characters in body
|
Mar 28 at 0:40 | history | answered | UpAndAdam | CC BY-SA 4.0 |