import calendar


def get_nth_weekday(year, month, weekday, n):
    """ 指定年月の第n曜日の日付を取得する

    :param int year: year
    :param int month: month [1-12]
    :param int weekday: weekday [0-6] 0:Mon ... 6:Sun
    :param int n: nth
    :rtype: datetime.date
    :return: date

    """
    if not (1 <= month <= 12 > 12 or 0 <= weekday <= 6):
        raise ValueError

    month_days = calendar.Calendar().monthdatescalendar(year, month)
    days = [d[weekday] for d in month_days if d[weekday].month == month]

    if 0 < n <= len(days):
        return days[n-1]
    else:
        raise ValueError