Python Forum
Help with "surrounding" a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with "surrounding" a string
#3
Below is one solution that works, just a number of simple
print statements in Python3

#!/usr/bin/env python
msg = input("Enter message:- ")
ch="*"
sp=" "
print(ch*(10+len(msg))) # print *
print(ch + (sp*(8+len(msg)))+ ch)
print("* " + msg + " *")
print(ch + (sp*(8+len(msg)))+ ch)
print(ch*(10+len(msg))) # print *
Below is the output:

Enter message:- Hello World
*********************
*                           *
*    Hello World     *
*                           *
*********************
You should be able to see how it works, it adds five "*" to beginning
and end of message, and adds a single "*" and four spaces to blank lines
Reply


Messages In This Thread
Help with "surrounding" a string - by jsirota - Oct-19-2017, 04:59 PM
RE: Help with "surrounding" a string - by cygnus_X1 - Oct-19-2017, 08:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020