Find the number of times every day occurs in a month | Python program to count occurrence of days in a month ; function to find occurrences ; stores days in a week ; Initialize all counts as 4. ; find index of the first day ; number of days whose occurrence will be 5 ; mark the occurrence to be 5 of n - 28 days ; print the days ; driver program to test the above function
import math NEW_LINE def occurrenceDays ( n , firstday ) : NEW_LINE INDENT days = [ " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " , " Sunday " ] NEW_LINE count = [ 4 for i in range ( 0 , 7 ) ] NEW_LINE pos = - 1 NEW_LINE for i in range ( 0 , 7 ) : NEW_LINE INDENT if ( firstday == days [ i ] ) : NEW_LINE INDENT pos = i NEW_LINE break NEW_LINE DEDENT DEDENT inc = n - 28 NEW_LINE for i in range ( pos , pos + inc ) : NEW_LINE INDENT if ( i > 6 ) : NEW_LINE INDENT count [ i % 7 ] = 5 NEW_LINE DEDENT else : NEW_LINE INDENT count [ i ] = 5 NEW_LINE DEDENT DEDENT for i in range ( 0 , 7 ) : NEW_LINE INDENT print ( days [ i ] , " ▁ " , count [ i ] ) NEW_LINE DEDENT DEDENT n = 31 NEW_LINE firstday = " Tuesday " NEW_LINE occurrenceDays ( n , firstday ) NEW_LINE