1

I am still on "Felipe’s Taqueria" problem, and I do not understand why I get the : "invalid decimal literal" error.

My code to print the result is as follwos:

print(f"$  { "{:.2f}".format(cost) }  ")
   

When I do this:

print("$" + "{:.2f}".format(cost))

This works.

But I would like to understand what is wrong with my f string.

2
  • 1
    go look at the docs for using fstrings in print.
    – UpAndAdam
    Commented Mar 11 at 15:43
  • I have read this doc on input, and from what I gather, it is not possible to use the f string literals combined to the str.format() method? Commented Mar 12 at 20:03

1 Answer 1

1

After reading the document recommended by @UpAndAdam, I think that the correct why to write what I wanted with f-strings is as follows:

print(f"${cost:.2f}")

I am sorry for this question!

It is true that when reading the documentation on this point it got clearer!!! Many thanks!

2
  • 1
    Nothing wrong with answering your own question. Shows you are growing and teaching yourself how to fish! Great job following through from the doc I sent you!!
    – UpAndAdam
    Commented Mar 13 at 3:51
  • Many many thanks for the kind words! I hope to keep progressing! Commented Mar 13 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .