Question: Assignment 1 contained the qualifier: There are some Python modules that can do this kind of calculation for you. You are expected to do the
Assignment contained the qualifier: "There are some Python modules that can do this kind of calculation for you. You are expected to do the calculation yourself for this assignment, without help from imported modules."
How easy was the assignment without this restriction? Let's repeat it in apy
Use the datetime.datetime.strptime function, to create a datetime object. Hint: Ymd
Instances of datetime have a timetuple method. It returns a "structtime" object, and a structtime has a tmyday attribute representing the day of year.
Use these facts to solve assignment in a few lines of code. A leap year example:
Enter a date in the form YYYYMMDD:
is day of the year
A nonleap year:
Enter a date in the form YYYYMMDD:
is day of the year
If strptime is given an invalid date it will raise a ValueError. Use that to handle invalid inputs.
Enter a date in the form YYYYMMDD: tomorrow
Invalid date.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
