468,291 Members | 1,717 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

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

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"?
Oct 23 '18 #1
0 920

Post your reply

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

Similar topics

reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.