Jan-16-2018, 04:49 PM
bottom line - because it teaches bad coding practices.
As Gribouillis said, repeating code, means you need functions. They also showed relatively complex, but better (in my opinion) than using
the way you want to name variables - day1, day2... etc is wrong, wrong, wrong! that's what data structures like dict, list, etc. are used for. What will you do if you have data for one year (365 days), or 10 years, or 50 yesrs...? will you create 3650 or 18250 variables? In this particular assignment it may work with several variables, in real - life - no. I doubt you are really restricted to using dict...
Showing a newbie how to do it, especially with eval, given that a newbie is not fully aware of possible side-effects... I would compare with giving a loaded gun in the hands of a toddler. Once you have data in per lists, I can imagine asking user for input to retrieve data back. And using eval will expose you to risk of running a user-supplied code you don't actually want to run. Yes, in this particular case, user will not supply malicious code. But again - it's a matter of teaching bad coding.
As Gribouillis said, repeating code, means you need functions. They also showed relatively complex, but better (in my opinion) than using
eval
approachthe way you want to name variables - day1, day2... etc is wrong, wrong, wrong! that's what data structures like dict, list, etc. are used for. What will you do if you have data for one year (365 days), or 10 years, or 50 yesrs...? will you create 3650 or 18250 variables? In this particular assignment it may work with several variables, in real - life - no. I doubt you are really restricted to using dict...
Showing a newbie how to do it, especially with eval, given that a newbie is not fully aware of possible side-effects... I would compare with giving a loaded gun in the hands of a toddler. Once you have data in per lists, I can imagine asking user for input to retrieve data back. And using eval will expose you to risk of running a user-supplied code you don't actually want to run. Yes, in this particular case, user will not supply malicious code. But again - it's a matter of teaching bad coding.