+ 11

Does anyone has some improvements?

I am making a simple age checker. You have to input your birthyear, birthmonth and birthday in this sequence seperated by an enter https://code.sololearn.com/c14c4SaIiX5P/?ref=app https://code.sololearn.com/c14c4SaIiX5P/?ref=app

7th May 2020, 1:07 PM
Vincenzinho
Vincenzinho - avatar
40 Respostas
+ 17
First of all: Really nice done! 👍 Here are some friendly hints from me: - Try to eliminate the use a separate print() statements per month. Put the month names in a dictionary. (see my sample code) - May be you can get a version where user can input his date of birth in one line like: 1980, 4, 18 - May be you also find a solution that uses always the current date instead of one fixed date. https://code.sololearn.com/c3JIRzJ0JdZa/?ref=app
7th May 2020, 2:36 PM
Lothar
Lothar - avatar
+ 13
I want to mention one thing: Regular names, like variables, functions, methods, should start with a lower case. Only class names start with a capital. That may seem unimportant, but everyone is used to that, and also the code will be colored differently. A more experienced coder will find that confusing.
7th May 2020, 1:17 PM
HonFu
HonFu - avatar
+ 7
Docstrings have the advantage that you can access them from the outside of whatever they're in. def f(): 'Hello' Now if you write help(f), you'll get to see this comment.
7th May 2020, 1:51 PM
HonFu
HonFu - avatar
+ 6
Okay thanks for the suggestion. I have changed it now
7th May 2020, 1:24 PM
Vincenzinho
Vincenzinho - avatar
+ 6
Vincenzinho, if you want to test how that would work: You can write print(help(__name__)) under your code. That's what you'd get to see if you called help on your module from the outside. If you want to hide some of the variables so that they don't appear in the output, just start them with _ and they will be ignored.
7th May 2020, 2:17 PM
HonFu
HonFu - avatar
+ 4
Its great! Would be cool if in the first print statement where it prints: "You were born on 3 12 1990" And instead of just the numbers, it printed for instance: "You were born on December 3rd, 1990"
7th May 2020, 1:15 PM
Slick
Slick - avatar
+ 4
Thanks, I will try to add that as well
7th May 2020, 1:17 PM
Vincenzinho
Vincenzinho - avatar
+ 4
Hah... relieving. 😅
7th May 2020, 1:24 PM
HonFu
HonFu - avatar
+ 4
Aha Thanks I did not know that and I added the suggestion now.
7th May 2020, 1:53 PM
Vincenzinho
Vincenzinho - avatar
+ 4
You may find this quite helpful: https://code.sololearn.com/cRqMcim7q00f/?ref=app Thank me later; best of luck buddy...
9th May 2020, 2:10 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
+ 3
Okay thanks HonFu and Code Crasher
7th May 2020, 2:21 PM
Vincenzinho
Vincenzinho - avatar
+ 3
Lothar Thanks it looks really nice but I have just begun the course and I have not had librarys and current dates yet. But when I learned that I will try to come back and implement it.
7th May 2020, 2:41 PM
Vincenzinho
Vincenzinho - avatar
+ 2
Thanks for the tip, but comments should be announced with an # right?
7th May 2020, 1:49 PM
Vincenzinho
Vincenzinho - avatar
+ 2
The timedate module will save you so much code
8th May 2020, 6:07 AM
ezequiel elias
+ 2
You can use this code to get current date,month,year automatically. https://code.sololearn.com/c3zTj0fxS23Y/?ref=app (I have modified the variable according to your code)
9th May 2020, 8:11 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 2
Thank you all for the suggestion. I know there is a function to update the latest times, but I am not so far in the module
9th May 2020, 10:40 AM
Vincenzinho
Vincenzinho - avatar
+ 2
Code Crasher Okay I have replaced them. Thank you for your help👍
9th May 2020, 11:02 AM
Vincenzinho
Vincenzinho - avatar
+ 2
Code Crasher 👍🏻
9th May 2020, 11:37 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 2
Vernim_ke Thanks for the suggestion. I have added it to the code. It Will now output a error if you enter an age above 130 years👍
11th May 2020, 6:47 AM
Vincenzinho
Vincenzinho - avatar
+ 1
Anjan Kalita Thanks for the suggestion. I added that as well now so if you input your year in the future it wil give an output that you can not be born in the future
8th May 2020, 9:50 PM
Vincenzinho
Vincenzinho - avatar