We will build a Python programme A1Q2.py to display formatted messages in this problem….

Sure, here is the Python program A1Q2.py that displays formatted messages based on the given instructions: ```python def display_message(): # Step 1: Ask user to input a string message user_input = input("Enter a string message, including your name and a short message (less than 40 characters): ") # Step 2: Ask user to input a field width greater than 40 width = int(input("Enter a positive integer greater than 40 as a field width: ")) # Step 3: Ask user to input an alignment method alignment = input("Enter an alignment method [left, right, center]: ") # Step 4: Format and display the message print("+" + "-" * width + "+") formatted_message = f"|{user_input:{alignment}{width-2}}|" print(formatted_message) print("+" + "-" * width + "+") # Call the display_message function display_message() ``` This program prompts the user to input a string message, a field width greater than 40, and an alignment method. It then formats and displays the message inside a box according to the given width and alignment. The box is created using '+' and '-' characters. Note that the program assumes valid inputs from the users, such as a string message that is less than 40 characters including the name, a positive integer greater than 40 as the field width, and a valid alignment method ('left', 'right', or 'center'). You can run this program by saving it as A1Q2.py and executing it using a Python interpreter.

We will build a Python programme A1Q2.py to display formatted messages in this problem.

Specifically:

1) Ask the users to input a string message which includes your name and a short message, i.e. ‘[Robert Kim] loves Hong Kong’. Make this entire message less than 40 characters, including your name. Put your name in the format: [first name] [Last name].
2) Ask users to input a positive integer that is greater than 40, which will serve as a field width subsequently.
3) Ask the user to input an alignment method [left, right or center].
4) Based on the following flow to write your code:

The sample output on different cases of input, the text in green indicates the user input or program output:
Alignment method
left
right
center
Wrong method
Output


Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.
Instant
Download
Student review: (4 ratings) 4 out of 4 people found this solution helpful.