0

i run this formating code print("%15s%.2f"%((heights[j])),end="") but i have this error what is the wrong here ??

TypeError: not enough arguments for format string

1
  • 2
    You have 2 placeholders and only one given variable. What is your expected output? Commented May 16, 2020 at 13:21

2 Answers 2

1

What does your heights looks like?

Here is a working example

heights = [("test",3.14)]
print("%15s%.2f"%((heights[0])),end="")

So heights must be a list of tuples or lists with 2 elements.

Sign up to request clarification or add additional context in comments.

1 Comment

height = (float(line[1]))
0

the first % formats the first value into the string and the second % formats the second value. The problem is you only have one value to format into the string (unless heights[j] is a list or tuple.

if you want heights[j to be formatted in both places, i suggest doing something like this:

print("{0}15s{0}.2f".format(heights[j]), end="")

this will replace every {0} in the string with the first argument passed to format()

2 Comments

but i need to round it i used before round() but the last decimal if its zero did not show eg. (1.70=1.7)
@juua if you know that the height is always one number (1.7/1.6/1.9 and not 12.5/20.2) you can cast you float to a string and check its length. if the length is 2, append a '0' to the end and then print is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.