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

8th May 2018, 2:46 PM
Omar
Omar - avatar
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
8th May 2018, 3:06 PM
Cool Codin
Cool Codin - avatar
+ 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())))
8th May 2018, 3:16 PM
Timon Paßlick
+ 2
0 -> c 1 -> a Because c is passed to format() as the first argument.
8th May 2018, 3:21 PM
Timon Paßlick
+ 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.".
8th May 2018, 3:37 PM
Timon Paßlick
+ 2
Also not the (Y|N) thing?
8th May 2018, 3:39 PM
Timon Paßlick
+ 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.
8th May 2018, 3:41 PM
Timon Paßlick
+ 2
Yes. Getting input is different.
8th May 2018, 3:43 PM
Timon Paßlick
+ 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.
8th May 2018, 3:45 PM
Timon Paßlick
+ 2
Try it in the code playground.
8th May 2018, 3:46 PM
Timon Paßlick
+ 2
Here I guess I sorted that issue of getting 1 year extra https://code.sololearn.com/cNvv4r5wjZK8/?ref=app
8th May 2018, 5:06 PM
Yugabdh
Yugabdh - avatar
+ 1
Where is code ? :)
8th May 2018, 2:57 PM
Yugabdh
Yugabdh - avatar
+ 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))
8th May 2018, 3:09 PM
Yugabdh
Yugabdh - avatar
+ 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))
8th May 2018, 3:17 PM
Yugabdh
Yugabdh - avatar
+ 1
Yes {} stands for 0 th also {0} stands for 0 th so I will prefer to use 2nd option
8th May 2018, 3:22 PM
Yugabdh
Yugabdh - avatar
+ 1
Omar o Mine is shorter and I discovered the bug with the wrong birth year.
8th May 2018, 3:23 PM
Timon Paßlick
+ 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.
8th May 2018, 3:29 PM
Timon Paßlick
+ 1
Ask the user if he already had birthday this year.
8th May 2018, 3:32 PM
Timon Paßlick
8th May 2018, 3:42 PM
Omar
Omar - avatar
+ 1
YUGABDH PASHTE It's not the first.
8th May 2018, 3:51 PM
Timon Paßlick
+ 1
hm..I see but what if you have to print same argument twice in an string then you can't avoid indexing
8th May 2018, 5:05 PM
Yugabdh
Yugabdh - avatar