+ 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
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
+ 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.
+ 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.
+ 6
Okay thanks for the suggestion. I have changed it now
+ 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.
+ 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"
+ 4
Thanks, I will try to add that as well
+ 4
Hah... relieving. 😅
+ 4
Aha Thanks I did not know that and I added the suggestion now.
+ 4
You may find this quite helpful:
https://code.sololearn.com/cRqMcim7q00f/?ref=app
Thank me later; best of luck buddy...
+ 3
Okay thanks HonFu and Code Crasher
+ 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.
+ 2
Thanks for the tip, but comments should be announced with an # right?
+ 2
The timedate module will save you so much code
+ 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)
+ 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
+ 2
Code Crasher Okay I have replaced them. Thank you for your help👍
+ 2
Code Crasher 👍🏻
+ 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👍
+ 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