8000 Conditional structures · neryuuk/learning-python@d42bbb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d42bbb7

Browse files
committed
Conditional structures
1 parent 658d8b5 commit d42bbb7

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

Ch2 - Basics/conditionals_finished.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

Ch2 - Basics/conditionals_start.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@
33
# LinkedIn Learning Python course by Joe Marini
44
#
55

6-
7-
86
def main():
97
x, y = 10, 100
108

119
# conditional flow uses if, elif, else
10+
if x < y:
11+
result = "x is less than y"
12+
elif x == y:
13+
result = "x is the same as y"
14+
else:
15+
result = "x is greater than y"
16+
print(result)
1217

1318
# conditional statements let you use "a if C else b"
19+
result = "x is less than y" if x < y else "x is greater or equal to y"
20+
print(result)
1421

1522
# match-case makes it easy to compare multiple values
1623
value = "one"
24+
match value:
25+
case "one":
26+
result = 1
27+
case "two":
28+
result = 2
29+
case "three" | "four":
30+
result = (3, 4)
31+
case _:
32+
result = -1
33+
print(result)
34+
1735

1836
if __name__ == "__main__":
1937
main()

0 commit comments

Comments
 (0)
0