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:
- Which line of code will be executed first by the computer when you run this code?
- What data structure is used to store a selection of European capital cities?
- What is the identifier of the procedure defined in this code?
- How many parameters this procedure takes?
- What programming construct is this procedure based on? Sequencing, Selection or Iteration?
- What data will be stored in the itemLength variable?
- What is the data type for this value: String, Boolean, Integer or Float?
- What data will be stored in the spaces variable?
- What is the data type for this value: String, Boolean, Integer or Float?
- 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
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.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area