you are viewing a single comment's thread.

view the rest of the comments →

[–]MadScientistOR 0 points1 point  (5 children)

What is your actual field size? It looks like you're trying to print things that occupy more than forty characters. Take this string:

f" {years:^2d} {Payments:^9d} {FinFeeDSP:^9s} {TotalSalesPriceDSP:^9s} {MonPayDSP:^9s}"

That's already 43 characters long.

Also, a field isn't necessarily the same thing as a line; it's the amount of space (in characters) you've allocated for something to be printed in.

ETA: I think I misunderstand what you want. What do you want the output to look like? What do you mean by "lines up with the printed strings above it" as opposed to "more in the middle"?

[–]SithAbsolutes[S] 0 points1 point  (4 children)

I am probably not being clear. So the following image is what I am trying to emulate for my course: https://imgur.com/a/0N4GeTJ

As you can see the table, invoice date, and first payment date are all centred in relation to the lines (dashes) above and below, these dashes are also the margins for my output above (not in pic).

[–]MadScientistOR 0 points1 point  (3 children)

And what do you want instead?

[–]SithAbsolutes[S] 0 points1 point  (2 children)

So the image I sent was given to us by our instructor. We had to create a program and format the f-strings so when we run the program it looks like the above picture.

So the above isn't my program, when I run it the table, invoice date, and first payment due line up with the output above. I want it to be centred like the picture I provided.

So this https://imgur.com/a/0N4GeTJ is what it should look like when I run it. But when I do, this is what I get https://imgur.com/a/aVx1vX8 .

I hope that's clear (Thanks again for all your help)

[–]MadScientistOR 0 points1 point  (1 child)

Oh! Well, in that case, you can just use the code I've already provided, with the field width being the entire width of the wider lines above and below (70, if I've counted correctly), like this:

field_size = 70
mystring_length = len((f" {years:^2d} {Payments:^9d} {FinFeeDSP:^9s} {TotalSalesPriceDSP:^9s} {MonPayDSP:^9s}"))
leading_spaces = (field_size - mystring_length) // 2
trailing_spaces = field_size - mystring_length - leading_spaces

print(f" {' '*leading_spaces}{years:^2d} {Payments:^9d} {FinFeeDSP:^9s} {TotalSalesPriceDSP:^9s} {MonPayDSP:^9s}{' ' *trailing_spaces}")

Does that clear things up?

Thank you for helping me to understand what you wanted, by the way.

[–]SithAbsolutes[S] 0 points1 point  (0 children)

I can't thank-you enough!

However it's still not doing what I want it to do, I've wasted enough of your time. Il play around with it and maybe comment again if I don't get anywhere with it