TDT4109/Exercise 4 - Inspera/11.py

32 lines
726 B
Python
Raw Permalink Normal View History

2020-10-01 12:05:45 +02:00
months = {
"januar": 31,
# "februar": 30,
"mars": 31,
"april": 30,
"mai": 31,
"juni": 30,
"july": 31, # Hmmm
"august": 31,
"september": 30,
"oktober": 31,
"november": 30,
"desember": 31
}
def myMonth():
while True:
try:
month = input('Skriv inn en måned: ').lower()
if month == 'februar':
year = int(input('Skriv inn et år: '))
assert ((year >= 0) and ( year <= 2020))
isLeapyear = year % 4 == 0
days = 29 if isLeapyear else 28
else:
assert month in months
days = month[month]
return f'Det er {days} dager i denne måneden'
except:
print('Ugyldig input! Prøv på nytt!')
print(myMonth)