S
Shiloh Madsen
Ok, so the chapter I am working on now is asking for me to write a
table of contents with the title left justified and the pages right
justified. I did this much earlier in the book with individual lines,
and it came out fine. The code I used initially was :
line_width = 60
puts ("Chapter 1: Getting Started".ljust(line_width/2) + "page
1".rjust(line_width/2))
puts ("Chapter 2: Numbers".ljust(line_width/2) + "page 9".rjust(line_width/2))
puts ("Chapter 3: Letters".ljust(line_width/2) + "page 13".rjust(line_width/2))
The chapter I am reading now is about arrays, so I am supposed to load
the same data into an array and accomplish the same task. What Ive
tried is several variations on this:
chapters = ['Chapter 1: Getting started','Chapter 2: Numbers',
'Chapter 3: Letters']
pages = ['page 1','page 9', 'page 13']
line_width = 60
puts (chapters.ljust(line_width/2) + pages.rjust(line_width/2))
...with the last line having changed a number of times. Obviously, I
haven't been able to get the code to run right. Could anyone tell me
what I am missing?
Shiloh
table of contents with the title left justified and the pages right
justified. I did this much earlier in the book with individual lines,
and it came out fine. The code I used initially was :
line_width = 60
puts ("Chapter 1: Getting Started".ljust(line_width/2) + "page
1".rjust(line_width/2))
puts ("Chapter 2: Numbers".ljust(line_width/2) + "page 9".rjust(line_width/2))
puts ("Chapter 3: Letters".ljust(line_width/2) + "page 13".rjust(line_width/2))
The chapter I am reading now is about arrays, so I am supposed to load
the same data into an array and accomplish the same task. What Ive
tried is several variations on this:
chapters = ['Chapter 1: Getting started','Chapter 2: Numbers',
'Chapter 3: Letters']
pages = ['page 1','page 9', 'page 13']
line_width = 60
puts (chapters.ljust(line_width/2) + pages.rjust(line_width/2))
...with the last line having changed a number of times. Obviously, I
haven't been able to get the code to run right. Could anyone tell me
what I am missing?
Shiloh