Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Formatted table with headings KameronG Programmer named Tim Posts: 6 Threads: 3 Joined: Feb 2019 Reputation: 0 Likes received: 0 #1 Feb-08-2019, 09:27 PM (This post was last modified: Feb-08-2019, 09:27 PM by KameronG. Edited 2 times in total.) Hello, I'm trying to have a program print the results from a formula into a formatted table, but I can't figure out how to get it to attach heading labels to the rows so it's clear what value is which. I have: ```if cs == "1": dA = d1 redshift = z dL = d1*(1 + z)**2 print(f"{redshift:13.3f} {dA:13.3f} {dL:13.3f}") else: dA = d2 redshift = z dL = d2*(1 + z)**2 print(f"{redshift:13.3f} {dA:13.3f} {dL:13.3f}") ```which gives me: ``````Output: 0.500 5.407 12.165 ``````I want it to say redshift, dA, and dL above the numbers but I can't find out how to do that anywhere. Larz60+ aetate et sapientia Posts: 7,406 Threads: 287 Joined: Sep 2016 Reputation: 264 Likes received: 1035 #2 Feb-09-2019, 12:38 AM you should always post enough of a code snippet so that it can be run, otherwise we can only approximate the proper answer assuming fields of 17 characters each: ```head = ['redshift', 'dA', 'dL'] print(f'{head[0]:17s} {head[1]:17s} {head[2]:17s}') ``` « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Multiplication Table funnybone04 4 892 Apr-08-2018, 03:03 AM Last Post: nilamo Table of Temperatures... Help zepel 18 3,914 May-07-2017, 08:48 AM Last Post: zepel

Forum Jump:

Users browsing this thread: 1 Guest(s)