1.7 KiB
1.7 KiB
id, source_exercise_id, title, section, source_path, source_repo, source_commit, student_visible_solution, has_private_solution, skip
| id | source_exercise_id | title | section | source_path | source_repo | source_commit | student_visible_solution | has_private_solution | skip |
|---|---|---|---|---|---|---|---|---|---|
| practical-python-2.11 | 2.11 | Adding some headers | 2.3 Formatting | 02_Working_with_data/03_Formatting.md | https://github.com/dabeaz-course/practical-python | 93dca856b41c61a0a0f85ae334116e4c125629ea | false | true | false |
Exercise 2.11: Adding some headers
Source: Practical Python Programming,
02_Working_with_data/03_Formatting.md.
Exercise 2.11: Adding some headers
Suppose you had a tuple of header names like this:
headers = ('Name', 'Shares', 'Price', 'Change')
Add code to your program that takes the above tuple of headers and creates a string where each header name is right-aligned in a 10-character wide field and each field is separated by a single space.
' Name Shares Price Change'
Write code that takes the headers and creates the separator string between the headers and data to follow. This string is just a bunch of "-" characters under each field name. For example:
'---------- ---------- ---------- -----------'
When you’re done, your program should produce the table shown at the top of this exercise.
Name Shares Price Change
---------- ---------- ---------- ----------
AA 100 9.22 -22.98
IBM 50 106.28 15.18
CAT 150 35.46 -47.98
MSFT 200 20.89 -30.34
GE 95 13.48 -26.89
MSFT 50 20.89 -44.21
IBM 100 106.28 35.84