0
Guys....plz see my last code and tell me if there is some thing wrong in the code☺
Plz donot delete this post again https://code.sololearn.com/cXiqohiS6ULZ/?ref=app
63 Answers
+ 3
Your code works perfectly fine. Good Job! 👍
Some Suggestions:
1. The int() function can be directly used with the input() function.
2. Try your best at using descriptive variable names instead of unambiguous names like a, b etc
+ 2
#Note that if you didn't have birthday yet this year, the year of birth is one too high.
import datetime
print("You were born in {}.".format(datetime.datetime.now().year-int(input())))
+ 2
0 -> c
1 -> a
Because c is passed to format() as the first argument.
+ 2
Yes, months and days are also possible. Ask either "Did you already have birthday this year? (Y|N)" or "Input your date of birth in MM.DD.YYYY format.".
+ 2
Also not the (Y|N) thing?
+ 2
I usually do C++, can't answer you this question. Thought 0 was first and 1 second, makes the most sense out of my perspective.
+ 2
Yes. Getting input is different.
+ 2
Omar o If you can't do any of those 2 options, never mind, you'll learn it soon enough. Just keep it up.
+ 2
Try it in the code playground.
+ 2
Here I guess I sorted that issue of getting 1 year extra
https://code.sololearn.com/cNvv4r5wjZK8/?ref=app
+ 1
Where is code ? :)
+ 1
code is fine just little improvements :
import datetime
a=int (input("enter your birth year"))
b=datetime.datetime.now().year
c=b-a
print("your age is {0} year".format(c))
+ 1
Like incase you are passing more than 1 argument then {} will always print 0 th argument
eg
print("your born in {1} age is {0} year".format(c,a))
+ 1
Yes
{} stands for 0 th
also {0} stands for 0 th
so I will prefer to use 2nd option
+ 1
Omar o Mine is shorter and I discovered the bug with the wrong birth year.
+ 1
I was born in 2002. My birthday is the third day of June. I'm 15 years old.
20018 - 15 = 2003
Wrong year of birth: I didn't have birthday yet this year.
+ 1
Ask the user if he already had birthday this year.
+ 1
Timon Paßlick yes
+ 1
YUGABDH PASHTE It's not the first.
+ 1
hm..I see but what if you have to print same argument twice in an string then you can't avoid indexing