1

while I read this

that has this code

We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.

when I revised to pep 498

print ("We can also do that this way:")
print (f"We'd have {secret_formula(start_point)} beans, {secret_formula(start_point)} jars, and {secret_formula(start_point)} crates.")

it print this

We can also do that this way:
We'd have (500000, 500, 5) beans, (500000, 500, 5) jars, and (500000, 500, 5) crates.
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
kunjun
  • 11
  • 1

2 Answers2

2

I see you are following LPTHW tutorial, which I strongly suggest you pick up a different tutorial, as the current one you have has some very interesting opinions and some other issues.

Back to your question: you need to unpack the secret_formula() call to be:

b, j, c = secret_formula(start_point)

print (f"We'd have {b} beans, {j} jars, and {c} crates.")

f-strings are basically just placing the variable in the string to call it and since the secret_formula() returns a tuple, when you fstring just calling the function, it will return and print the tuple.

MooingRawr
  • 4,901
  • 3
  • 24
  • 31
0

this code I want to fix into f-string print "We can also do that this way:" print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)

kunjun
  • 11
  • 1