Proper way of coding - mean variance standard exercise


So I’ve completed the Mean-Variance-Standard Deviation Calculator but I’m curious about the proper way of coding it.

Would it be better to assign values to individual variables and then call the variables in the output matrix, rather then simply stating the equations directly in the matrix? (like I’ve done and you can see in the project link).

If it were a “proper” program, how would the code likely be structured?

Thanks for any input,

Your project link(s)


Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

The most important thing is that the code actually works the way you wanted it to work.
Your code looks clean. I only suggest checking out the PEP8 guidelines for writing code to learn about doc strings, spacing, indentation, and more. Better yet, use something like Syntastic plugin (or equivalent) in your editor to help you format the code while you type. I use Syntastic in my editor, I loaded your code there and got a few warnings.

But what is proper? :slight_smile:

I’d try to focus on making it simpler and more clearer. That’s easier to assess than referring to doing something in a proper way. Do you see any places that can be simplified? What’s hard to understand in it? Any repeated parts?

Hi, thanks for the reply and the advice
Syntastic sound interesting, I’ll check it out!!

Yeah, I know that’s why I wrote “proper”. And actually it was still a poor choice of words. What I’m looking for is readability I guess. As in, if I hand it over to someone else, will they be able to understand what has been done.

I think in this case it is quite simple, and i’m not sure how much less code I could’ve used to get the results. So my thought was, maybe I should have expanded the code a bit, to make it easier to understand, by introducing some variables first, which would also make it easier to call said variables if I were to expand the code in the future.

Thank you for your reply!

As you say, there isn’t really anything complex here, just a dictionary with some strings as key and list as value.

Take a look a it from the angle of what would be required to add another calculation: that’s one string, a list, with three basically the same function calls that needs to go somewhere in the dictionary.

Similar pattern repeats for every entry. What differs is the string, and the function, the actual parameters of each function call are the same. Does this give you any ideas?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.