-1

Can someone please help me create a function that prints a dashed border around text the user enters. I know it has to identify the length of a string so it can adjust accordingly around the entered text but I don't know how to do that.

So far I have:

my_string = raw_input("Enter some text:")
len(my_string)
for i in my_string:
  print my_string

def border():
  dash = "-"

border()

The final result should look something like this:

--.----.-----------

.                 .
-   Hello         -
.                 .


--.-----.---------.
Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
alexa
  • 3
  • 1
  • you have already identified the length of the text. thats what len(my_string) does. I dont see what the problem is. – Jacobr365 May 17 '18 at 14:39
  • 2
    Possible duplicate of [Dynamic border around text in python](https://stackoverflow.com/questions/35381065/dynamic-border-around-text-in-python) (The answer to OP's question is in the other user's question.) – Thomas Cohn May 17 '18 at 14:40
  • 1
    Welcome to StackOverflow. However, it is important that your question be clear. Your final given result is not clear. Why are there some non-dash characters in the top and bottom borders? What exactly do you want on the left and right sides of the original string? – Rory Daulton May 17 '18 at 14:41
  • What determines the placement of the dots in the top and bottom edges? – chepner May 17 '18 at 14:48
  • @RoryDaulton I just put the dots because the dashes weren't showing up without them, but the problem is that when the code is run it doesn't give me a end result of what i said the final result should be – alexa May 17 '18 at 16:58
  • My point is that you said very little about what "the final result should be." The example output also did not match what little you said. Questions here should have enough detail so a potential answerer can understand exactly what you meant. – Rory Daulton May 17 '18 at 21:20
  • @Rory Daulton that’s because I had no idea how to go about with this code and the Dynanamic border around text in python question on this website doesn’t help either because that’s not what I’m looking to do. – alexa May 18 '18 at 03:53
  • @RoryDaulton. But if you have no idea and can’t help then never mind, but thanks for your feedback anyways . – alexa May 18 '18 at 03:54

1 Answers1

0

Let's give you a first code to start with. It may answer to your question, but you should learn more to improve it and use it for your final usage:

def border(s):
    dash = "-"
    print(dash * (len(s) + 4))
    print(dash + " " + s + " " + dash)
    print(dash * (len(s) + 4))

my_string = input("Enter some text: ")
border(my_string)
Laurent H.
  • 6,316
  • 1
  • 18
  • 40