Hi, I want to make a program that can make asterisks around the text, so the output is something like this:

Enter string: Hello World

*************
* Hello World *
*************

I do not want to use the multiplication technique (ex: "*" * 5), and I want to try using a while loop for this, not anything else.

Current code is:

s = raw_input("Enter a string: ")

loop = True
#for the asterisks? i'm not sure
s_output = ""

#don't know what to do here, confused about what conditions to give
while loop:

Recommended Answers

All 7 Replies

Have a fiddle around with

count = 0

while count <= len(s)+2:
    count +=1
    print '*'

That should print out that right amount of asterisks. See if you cant take that a bit further :)

Member Avatar for masterofpuppets

not sure if this is what you're trying to do :):

s = raw_input( "Enter string>> " )
count = 0
while count < len( s ) + 2:
    print "*", #this allows the next character to be printed on the same line
    count += 1

print #print statement is needed to go to next line
print "* " + s + " *"
count = 0 #restart the counter, or use other variable
while count < len( s ) + 2:
    print "*",
    count += 1

Yes, i think that is what they are trying to do, but at daniweb we try to not give outright answers for the questions and rather steer users in the right direction so that they may learn by themselves :)

Member Avatar for masterofpuppets

oh right :) sorry about that. I'll try to do that next time :)

Hint, you may want to use string concatenation to form the solid line of asterisks. Once the string is formed you can use it for top and bottom.

I'm wondering why is there a requirement that the code be written using a while loop?

Is it a requirement as part of an assignment?

Is it just to learn the while loop better?

Is it a personal belief that the while loop is a better or the best method to use? It may well be. I'm just curious.

hi i need to make a program about parking lot. 5 cars are park and i need to let it in,out and make an exit of it using asterisk...pls help....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.