Please helo me to use python write this code thanks Write a

Please helo me to use python write this code, thanks.

Write a method center that takes a string st and a field size width and returns a centered version of the string within the given field. Add spaces to each side of st to center it. Note: . You can find the number of characters in a string with len (st) . st is guaranteed to contain an even number of characters. width is also guaranteed to be even width may be less than len(st). In this case just return the original string.

Solution

def main():

st=input(\'enter a string :\')

width=input(\'enter width:\')

print center(st,width)

def center(st,width):

if(width>len(st)):

for i in range(1,(width-len(st))/2+1):

st=\" \"+st+\" \";

return st

#as shown in above code append empty spaces on #both sides of string input if the width is greater than #length of string

Please helo me to use python write this code, thanks. Write a method center that takes a string st and a field size width and returns a centered version of the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site