A small code example

Below is a short snippet of Python code for you to try and read. Don't worry if you can't understand it completely at first, once you get enough practice, it'll all make more sense in no time at all:

# My typical meal is comprised of:
nachos = 4.50
taco = 1.50
horchata = 1.00
subtotal = (1 * nachos +
            3 * taco +  # Sometimes 4 or 5 :)
            1 * horchata)

# Here in San Francisco, the tax rate is 8.75%!
# Crazy, right?!
tax_rate = 0.0875
total = subtotal * (1.0 + tax_rate)

print('Your total is:')
print(total)

Some thought exercises:

  • Can you guess what this code does?
  • What do you think nachos = 4.50 means?
  • What do you think happens when you run this program?

results matching ""

    No results matching ""