-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3.1.1.12Lab.py
72 lines (51 loc) · 1.84 KB
/
3.1.1.12Lab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
Estimated time
10-25 minutes
Level of difficulty
Easy/Medium
Objectives
Familiarize the student with:
using the if-elif-else statement;
finding the proper implementation of verbally defined rules;
testing code using sample input and output.
Scenario
As you surely know, due to some astronomical reasons, years may be leap or common.
The former are 366 days long, while the latter are 365 days long.
Since the introduction of the Gregorian calendar (in 1582), the following rule is used
to determine the kind of year:
if the year number isn't divisible by four, it's a common year;
otherwise, if the year number isn't divisible by 100, it's a leap year;
otherwise, if the year number isn't divisible by 400, it's a common year;
otherwise, it's a leap year.
Look at the code in the editor - it only reads a year number, and needs to be completed
with the instructions implementing the test we've just described.
The code should output one of two possible messages, which are Leap year or Common year,
depending on the value entered.
It would be good to verify if the entered year falls into the Gregorian era, and output
a warning otherwise: Not within the Gregorian calendar period. Tip: use the != and % operators.
Test your code using the data we've provided.
Test Data
Sample input: 2000
Expected output: Leap year
Sample input: 2015
Expected output: Common year
Sample input: 1999
Expected output: Common year
Sample input: 1996
Expected output: Leap year
Sample input: 1580
Expected output: Not within the Gregorian calendar period
'''
# solution
year = int(input("Enter a year: "))
if year < 1582:
print("Not within the Gregorian calendar period")
else:
if year % 4 != 0:
print("Common year")
elif year % 100 != 0:
print("Leap year")
elif year % 400 != 0:
print("Common year")
else:
print("Leap year")