Python: A question in exercise 5. Total, in Tip Calculator related to % in the print statement


#1

This is the link of the exercise i have been performing.
https://www.codecademy.com/courses/python-beginner-GB6hM/0/5?curriculum_id=4f89dab3d788890003000096

There is no error message, i have a question regarding the below code

print("%.2f" % total)

In the above code "%.2f" is used to show 2 digits after the point.
here f is float data type??

And why have we use % total, total is to print the total but what is the use of %??


#2

look:

"%f" % total

we can use %f as placeholder in a string, then at the end of the string, we add a % (this is just syntax) to let python know we are going supply variable for which we added placeholders inside the string


#3

i didn't get u...
can u elaborate?plz


#4

can you elaborate on what you don't understand?


#5

Problem solved brother, thank you for ur help.

<
https://ci6.googleusercontent.com/proxy/hBQdSBMI7GMZcdf5abIXHQiM6pw_SVXEvVeBIT5HzGfvhC_LP8XHiHm7AtDmtWqedANOuwEVcIpFiA81akj3Lx1FJ3NPhA1wY9tZZG1PfP5GjMzBV1VaMun088KqaAR7efhKMEB12BnthdkNDleSEQ2csx6UmFbXh23PlfAnOGhD=s0-d-e1-ft#https://discourse-cdn-sjc1.com/codecademy/user_avatar/discuss.codecademy.com/stetim94/45/692217_1.png>
stetim94 Codecademy Moderator
March 3

can you elaborate on what you don't understand?


Visit Topic or reply to this email to respond.


In Reply To

<
https://ci6.googleusercontent.com/proxy/mwC9-98XWlm4ki92mgBBOMdl99kcoHUiCWTHon_liPJR4dBGz0NkG_a79iZKrvqRihqpBBN4Zwh2dOdPRmlkTYvvDu-CzZjQHzO7gI7Ny4mnAQRiV4PI0qfaH7PC1UQlFLw8pucDUZuyWVvTPKoRdfS27rUfO1jOzzm-6ZwZixjy5nVs3HG2kqjI3w=s0-d-e1-ft#https://discourse-cdn-sjc1.com/codecademy/user_avatar/discuss.codecademy.com/cloudblaster41086/45/6523633_1.png>
cloudblaster41086


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.