By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,583 Members | 3,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,583 IT Pros & Developers. It's quick & easy.

Finding number of days in month from a text file without using "if"

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 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"?
Oct 23 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.