-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay15.py
More file actions
30 lines (22 loc) · 905 Bytes
/
Day15.py
File metadata and controls
30 lines (22 loc) · 905 Bytes
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
# Match CASE statement
# To implement Switch-case like characteristics very similar to if-else functionality, we use Match case
# A Match statement will compare a given variable's value to different shapes, aka patters.
# The main idea is to keep on comparing the variable with all the present patterns until it fits into one.
# The match case consists of three main entities:
# The Match keyword
# One or more case clauses
# Expression for each case
x = int(input("Enter the value of x: ")) # x is the variable to match
match x:
case 0:
print("X is Zero")
# case with if-condition
case 4 if x % 2 == 0:
print("x % 2 == 0 and case is 4")
# Empty case with if-condition
case _ if x < 10:
print("x is < 10")
# default case (will only be matched if the above case were not matched)
# so it is basically just and else:
case _:
print(x)