()
| 6 | |
| 7 | |
| 8 | def main(): |
| 9 | x, y = 10, 100 |
| 10 | |
| 11 | # conditional flow uses if, elif, else |
| 12 | if x < y: |
| 13 | result = "x is less than y" |
| 14 | elif x == y: |
| 15 | result = "x is same as y" |
| 16 | else: |
| 17 | result = "x is greater than y" |
| 18 | print(result) |
| 19 | |
| 20 | # conditional statements let you use "a if C else b" |
| 21 | result = "x is less than y" if (x < y) else "x is greater than or equal to y" |
| 22 | print(result) |
| 23 | |
| 24 | # new in Python 3.10 |
| 25 | # the match-case construct can be used for multiple comparisons |
| 26 | value = "one" |
| 27 | match value: |
| 28 | case "one": |
| 29 | result = 1 |
| 30 | case "two": |
| 31 | result = 2 |
| 32 | case "three" | "four": |
| 33 | result = (3, 4) |
| 34 | case _: |
| 35 | result = -1 |
| 36 | print(result) |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | main() |
no outgoing calls
no test coverage detected