Esempio n. 1
0
def print_birthdays(filename):
    '''This function accepts a string filename as a parameter,
       the function then opens and reads the file - when the
       input is 'birthdays.txt' - the file print the person’s name,
       birthday, and the day of the week on which the person was born.
       '''
    file = open(filename, 'r')

    for line in file:
        categories = line.split(',')
        name = categories[0]
        month = int(categories[1])
        day = int(categories[2])
        year = int(categories[3])
        newdate = Date(month,day,year)
        y = newdate.day_of_week()
        print(name +" (" + str(newdate) + ")" + " ("+ str(y) + ")")
Esempio n. 2
0
def print_birthdays(filename):
    ''' accepts a string filename as a parameter. The function should then open the file that corresponds to that filename, read through the file, and print some information derived from that file.
    '''
    
    file = open(filename, 'r')
    for line in file:
        line = line[:-1]
        
        fields = line.split(',')
        name = fields[0]
        new_month = int(fields[1])
        new_day = int(fields[2])
        new_year = int(fields[3])
        d = Date(new_month, new_day, new_year)
        day = d.day_of_week()


        print(name + ' ' + '(' + str(d) + ')' + ' ' + '(' + day + ')')
        
    file.close()
Esempio n. 3
0
def nye_counts(start, end):
    
    """This function counts and prints how many times New Year’s Eve
      falls on each day of the week between the years start and end."""

    counts = {}
    counts['Sunday'] = 0
    counts['Monday'] = 0
    counts['Tuesday'] = 0
    counts['Wednesday'] = 0
    counts['Thursday'] = 0
    counts['Friday'] = 0
    counts['Saturday'] = 0

    for year in range(start, end + 1):
        newdate = Date(12,31,year)
        y = newdate.day_of_week()
        #print(y)
        counts[y] += 1

        
    print(counts)