Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.32 KB

flow-control.mdx

File metadata and controls

48 lines (36 loc) · 1.32 KB
title
Flow control

import CodeBlock from '@theme/CodeBlock';

if-else condition

age = 33

if (age >= 18):
    print("You are adult person.")
else:
    print("You are not an adult yet.")

You can have multiple conditions with elif statements:

age = 70

if (age >=18 and age <65):
    print("You are adult person.")
elif (age >=65):
    print("You are a senior.")
else:
    print("You are not an adult yet.")

Now try with different age to see the results yourself. Note the use of and to combine conditions. In case of if/else condition check, once a if condition is satisfied, the code exits there, it does not check for next conditions.

Tax calculator

Another practical example: calculate personal income tax for Singapore residents.

import sg_tax_calculator from '!!raw-loader!/src/sg_tax_calculator.py'

{sg_tax_calculator}

Tax rates are correct as of January 2022. Please check with IRAS website.

:::tip

If you want to calculate your tax right now on the browser, you can use this web app.

:::