Last active
March 25, 2023 22:33
-
-
Save 3urobeat/01671e4eec048ba75861ad6f323b5988 to your computer and use it in GitHub Desktop.
Automata theory date checking task from school as program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Automata theory task from school as quick & small a program | |
# A company wants to award employees who started working in the company in the year 2006 with a pay bonus. | |
# Probably a lazy way to do it but works great for only 12 months | |
thirtymonths = ["04", "06", "09", "11"] | |
thirtyonemonths = ["01", "03", "05", "07", "08", "10", "12"] | |
print("When did you start working in this company?\nPlease input your date (DD.MM.YYYY): ") | |
datearray = input().split(".") # Stops execution of the whole program until input was submitted | |
# Datearray needs to have the length of 3 otherwise something is missing | |
if len(datearray) != 3: | |
print("You input seems to be incorrect. Please respect the formatting.") | |
exit() | |
# Define arr entries as variables to make them easier to access, convert to int and catch exception if user's input was garbage | |
try: | |
day = int(datearray[0]) | |
month = int(datearray[1]) | |
year = int(datearray[2]) | |
except: | |
print("You input seems to be incorrect. Please respect the formatting.") | |
exit() | |
# Check if day is positive | |
if day < 1: | |
print("The day you enter must be greater than 0!") | |
exit() | |
# Check if month is positive and not greater than 12 (Aliens are not supported, Sorry!) | |
if month > 12 or month < 1: | |
print("The month you enter must be greater than 0 and smaller than 12!") | |
exit() | |
# Only year 2006 is allowed so stop don't even bother checking anything else | |
if year != 2006: | |
print("You aren't allowed to be awarded a bonus.") | |
exit() | |
# Check if day matches max days in month | |
if month in thirtymonths: # month with 30 days | |
if day > 30: | |
print(f"The month {month} has only 30 days.") | |
exit() | |
elif month in thirtyonemonths: # month with 31 days | |
if day > 31: | |
print(f"The month {month} has only 31 days.") | |
exit() | |
elif datearray[1] == "02": # 2006 was not a leap year so February had 28 days | |
if day > 28: | |
print(f"The day {day} you entered is invalid!") | |
exit() | |
print("You are allowed to be awarded a bonus!") # Hurray 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment