Bassam Badr Bassam Badr - 1 year ago 67
Python Question

prints the string with enough leading spaces?

Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5.

Write a function named right_justify that takes a string named s as a parameter and prints the string with enough leading spaces so that the last letter of the string is in column 70 of the display.

>>> right_justify('allen')

I solved it like this

def right_justify(s):
print " " + s


Is it right ????
is there any specific function can do spaces the long that we want??

sorry for my bad english

Answer Source

Its quite easy with string formatting:

def right_justify(s):
    print "%70s" % s
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download