162k views
0 votes
The PadRight function has two parameters: S (a string) and N (an int), and returns as its result the string S padded on the right with blanks until the length of S contains no fewer than N characters. The PadLeft function is identical to PadRight except that it adds blanks to the left side of the string. For example, the string "Frog" is four characters long, so PadLeft("Frog",7) would return the

User Ian Dunn
by
4.8k points

1 Answer

5 votes

Answer:

The following code is written in python programming language:

def PadRight(S,N): #define user defined function

if(len(S)<N): # set if condition

S=S.ljust(N) #set the space to right

return S # return the result

def PadLeft(S,N): #define user defined function

if(len(S)<N): # set if condition

S=S.rjust(N) # set the space to left

return S # return the result

'''calling the function'''

print(PadLeft("Frog",7))

print(PadRight("Frog",7))

Output:

Frog

Frog

Step-by-step explanation:

Here, we define a user defined function "PadRight()" and pass two arguments in its parameter "S", "N".

Then, set the if condition and pass condition "len(S)<N" then, if the condition is true then the code inside the if condition set the space to right then, return the output.

After that, we again define a user defined function "PadLeft()" and pass two arguments in its parameter "S", "N".

Then, set the if condition and pass condition "len(S)<N" then, if the condition is true then the code inside the if condition set the space to right then, return the output.

User Jay Mathis
by
4.9k points