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 1 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 a1.py.
Use the datetime.datetime.strptime function, to create a datetime object. Hint: "%Y/%m/%d".
Instances of datetime have a .timetuple() method. It returns a "struct_time" object, and a struct_time has a tm_yday attribute representing the day of year.
Use these facts to solve assignment 1 in a few lines of code. A leap year example:
Enter a date in the form YYYY/MM/DD: 2024/05/03
2024/05/03 is day 124 of the year 2024.
A non-leap year:
Enter a date in the form YYYY/MM/DD: 2023/05/03
2023/05/03 is day 123 of the year 2023.
If strptime is given an invalid date it will raise a ValueError. Use that to handle invalid inputs.
Enter a date in the form YYYY/MM/DD: tomorrow
Invalid date.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!