Text Alignment Challenge


This challenge focuses on the use of string manipulation techniques in order to format the output when printing text on the screen.

Step 1: Reverse Engineering


First look at the code provided above and use this code to answer the following questions:

  1. Which line of code will be executed first by the computer when you run this code?
  2. What data structure is used to store a selection of European capital cities?
  3. What is the identifier of the procedure defined in this code?
  4. How many parameters this procedure takes?
  5. What programming construct is this procedure based on? Sequencing, Selection or Iteration?
  6. What data will be stored in the itemLength variable?
  7. What is the data type for this value: String, Boolean, Integer or Float?
  8. What data will be stored in the spaces variable?
  9. What is the data type for this value: String, Boolean, Integer or Float?
  10. String concatenation is the act of joining two strings together (using the + sign). Which line of code is using string concatenation is this program?

Step 2: Complete the Code


Using a similar approach to the code given to implement the leftAlign procedure create two more procedures as follows:

  • rightAlign to display all the European capitals aligned to the right.
  • centerAlign to display all the European capitals centred on screen.

Step 3: Extension Task Task


-lorem ipsum.txt –

Write a Python program to read and display the content of the above text file:

  • Align to the left,
  • Align to the right,
  • Centred,
  • Justified,
  • Using Auto-hyphenation.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members Area
Tagged with: