FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programmingWithPythonCode/conditionals/if_else_example.py at main · thomasWeise/programmingWithPythonCode · GitHub
thomasWeise
programmingWithPythonCode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programmingWithPythonCode
/
conditionals
/
if_else_example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
19 lines (16 loc) · 1009 Bytes
Breadcrumbs
programmingWithPythonCode
/
conditionals
/
if_else_example.py
Copy path
File metadata and controls
19 lines (16 loc) · 1009 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""An example of using the `if-else` statement."""
year
:
int
=
2024
# the year 2024 should be a leap year
if
(((
year
%
4
)
==
0
)
and
((
year
%
100
)
!=
0
))
or
((
year
%
400
)
==
0
):
print
(
f"
{
year
}
is a leap year."
)
# This line will be executed.
print
(
"yes, it really is."
)
# This line as well.
else
:
# If we get here, it's not a leap year.
print
(
f"
{
year
}
is not a leap year."
)
# This line is never reached.
print
(
"Believe you me, it indeed is not."
)
# also never reached.
year
=
1900
# the year 1900 is not a leap year
if
(((
year
%
4
)
==
0
)
and
((
year
%
100
)
!=
0
))
or
((
year
%
400
)
==
0
):
print
(
f"
{
year
}
is a leap year."
)
# This line is never reached.
print
(
"yes, it really is."
)
# This line is never reached.
else
:
# If we get here, it's not a leap year.
print
(
f"
{
year
}
is not a leap year."
)
# This line will be executed.
print
(
"Believe you me, it indeed is not."
)
# This line too.
print
(
"End of year checking."
)
# This text is always printed.
Back
|
FazBrowse Home
|
New Git URL