P: 1
|
Write the number of days in months program so that the program prompts the user for the file name and reads the dates from the file.
The dates in the file are written in the format dd.mm.yyyy. The program looks for the month in each line (hint: use split) and prints out the number of days in that month.
Rewrite the function so that it does not contain conditional (if) statements for returning the number of days. The function should do it using a list. Do not add the check for a leap year (let’s say that there are 28 days in February).
I have this code:
dates = {}
file = input("Enter file name:")
file = open("dates.txt", "r")
for line in file:
month = line.split(".")
dates = month[1]
print (dates)
But it only reads the month from the text file. How do I add another formula to read the months and state the days instead, within this code without using "IF"?
| |
Share this question for a faster answer!