What is this syntax?


#1

What is bill *
Should it not be bill

def tax(bill):
    """Adds 8% tax to a restaurant bill."""
    bill *= 1.08
    print "With tax: %f" % bill
    return bill

def tip(bill):
    """Adds 15% tip to a restaurant bill."""
    bill *= 1.15
    print "With tip: %f" % bill
    return bill
    
meal_cost = 100
meal_with_tax = tax(meal_cost)
meal_with_tip = tip(meal_with_tax)

#2

Also, when formatting with strings using %, does it matter if you use %d or any other letter instead of %f.
Also, why is %f not % to coincide with % (bill). What is the significance of the f in %f ?


#3

%f is most certainly important, it indicate float numbers. You can read about it here


#4

Oh, so the letter indicates the type of the data. Thank you!!!!!!


#5

Also,

What is bill *

Should it not be bill


#6

yes it does

i don't see what you are referring to.


#7

On line 3 it says

bill *= 1.08

What does *= mean?

Thank you.


#8

i can't conclude from bill * that you mean bill *= 1.08. It is a nice little shorthand, this is without shorthand:

bill = bill * 1.08

you basically update (re-assign) the current stored value multiplied by 1.08, in the same variable name. Really useful.