2
rotho98
5y

So I'm relatively new to Python. I've started doing the practicepython.org challenges. What do you guys think to my code layout, is there any way I can improve.
https://github.com/Rotho98/...

Comments
  • 2
    hmm, it looks like you’re new to coding in general. ex1 and ex2 look fine.

    Instead of using format, use f strings: https://realpython.com/python-f-str...

    Work on more substantial problem. Whenever I learn a new language, I like to overengineer a simple problem with more advanced features (regex, lambdas, function pointers, etc).
  • 0
    @toriyaki thank you, I will have a look at f strings. I can see how they can make cleaner looking code
  • 1
    First example has a typo: your should be you and the function is wrong...

    If I am 8 and I turn 9 tomorrow. It would say the year where I turn 101 instead of 100 😉
  • 1
    @mpie thanks for pointing the typo. To stop the date confused I ask the user what age they turn this year. Obviously I could implement something that looks of the date and month have already past. If it hasn't add 1 to the year count
  • 1
    Also make your code readable.
    Instead of:
    if num % 2 == 0 and num % 4 == 0:

    Do:
    if (num % 2) == 0 and (num % 4) == 0:
    I know it’s not necessary in Python, but there are more languages out there. Might help you in the future.
Add Comment