Answer:
This program is written using Python Programming Language;
Comments are not used; however, see explanation section for detailed line by line explanation
See Attachment
Program starts here
def align_right(a_string,string_length):
if len(a_string) > string_length:
print(a_string)
else:
aligned=a_string.rjust(string_length)
print(aligned)
a_string = input("Enter a string: ")
string_length = int(input("Enter string length: "))
align_right(a_string,string_length)
Explanation:
Function align_right is declared using on line
def align_right(a_string,string_length):
This line checks if the length of the current string is greater than the input length
if len(a_string) > string_length:
If the above condition is true, the input string is printed as inputted
print(a_string)
If otherwise,
else:
The string is right justified using the next line
aligned=a_string.rjust(string_length)
The aligned string is printed using the next line
print(aligned)
The main function starts here
This line prompts user for a string
a_string = input("Enter a string: ")
This line prompts user for total string length
string_length = int(input("Enter string length: "))
This line calls the defined function
align_right(a_string,string_length)