Write A Python Script To Print String With Prefix Of Ten Spaces By Using Format

Given an input string to the Python program your task is to to accept an input string from the user and add prefix to it.  The prefix should be 10 spaces.

The prefix string is a string that is placed before another string.

 

Write A Python Script To Print String With Prefix Of Ten Spaces By Using Format

 


Write A Python Script To Print String With Prefix Of Ten Spaces By Using Format

Take a  string variable  name 10 text and ask a user to enter a string using the input function call,   what's the user enter setting using the print function call. Once the user enters a string, use the print function call  to print a user-friendly message that is a new string after  prefixing 10 spaces.

text = input("Enter a String : ")
print("New String After prefixing 10 spaces to string ...")




You have to use the format function call to to add 10 spaces as a prefix to the given input string so take a variable named as restart and use the flower braces to to provide the arguments as spaces and the the input string.

result = "{0}{1}".format(" " * 10, text)
print(result)





Complete python code
=============================

text = input("Enter a String : ")
print("New String After prefixing 10 spaces to string ...")
result = "{0}{1}".format(" " * 10, text)
print(result)






Output
==========
Enter a String : hey
New String After prefixing 10 spaces to string ...
          hey





Output
=============
Enter a String : hello
New String After prefixing 10 spaces to string ...
          hello




Output
==============
Enter a String : this is my string
New String After prefixing 10 spaces to string ...
          this is my string





Conclusion
=================
Execute the Python program by providing a different set of input strings and then note down the result.  comment it down below if you have any suggestions to improve the above Python program

Post a Comment

0 Comments