Can someone explain '% bill' this part?


#1

can someone explain '% bill' this part?

it was used in the tip calculator.


#2

Hi John,
I just joined today and started. What exactly is the problem you are having? I may or may not be abel to help but I will try, you may be able to help me at somepoint as well :smile:


#3

Not sure if you meant this line
print("%.2f" % total)

if so this is saying to print the variable total(which was defined earlier in the code)

and the %2f is saying to print total as a floating number with 2 decimal points


#4

It's just saying that 'use the value of bill'.

When you use bill, you write it as:

print "This is a value: %d" % bill

If you have more than one value, you'll write something like this:

print "These are values: %d %d" % (onevalue, othervalue)

This is assuming that bill is a variable, as well as onevalue and othervalue.


#5

Also, if you know C, then it's similar to calls to printf.

printf("This is a value: %d", bill);
is the same as
print "This is a value: %d" % bill


#6

Got it ! thank you so much :smiley:


#7

hi maherpa2,
cst1992 explained it below. Thats exactly what i was looking for. But thank you. :smiley: