Case9. Two integers are given: D (day) and M (month), which determine the correct date of a non-leap year. Output the values of D and M for the date following the specified date.

Solution in Python 3:

import random

M = random.randrange(1,13)
#M=12
month = {
1: 31,
2: 28,
3: 31,
4: 30,
5: 31,
6: 30,
7: 31,
8: 31,
9: 30,
10: 31,
11: 30,
12: 31
}
try:
D_Max = month[M]
D = random.randrange(1,D_Max+1)
#D = 31
print("Date:")
print("Month: {0}. Day: {1}".format(M,D))
if D < D_Max:
D += 1
else:
D = 1
if M == 12:
M = 1
else:
M +=1
print("Following date:")
print("Month: {0}. Day: {1}".format(M,D))
except KeyError as e:
print('Error')