I want to combine two of my print statement so that it has no gap in between. How do I remove gap after break? This is my code: - alpha1 = 'a'
-
n = 6
-
while alpha1:
-
n -= 1
-
print "%-*s" % (10, alpha1*n) + "%*s" % (10, alpha1*n)
-
if n < 0:
-
break
-
m = 0
-
while alpha1:
-
m += 1
-
print "%-*s" % (10, alpha1*m) + "%*s" % (10, alpha1*m)
-
if m > 4:
-
break
The out put will be: - aaaaa aaaaa
-
aaaa aaaa
-
aaa aaa
-
aa aa
-
a a
-
-
a a
-
aa aa
-
aaa aaa
-
aaaa aaaa
-
aaaaa aaaaa
-
How do I remove the gap so that the output will be like this? - aaaaa aaaaa
-
aaaa aaaa
-
aaa aaa
-
aa aa
-
a a
-
aa aa
-
aaa aaa
-
aaaa aaaa
-
aaaaa aaaaa
-
You need only change two of the numbers. - alpha1 = 'a'
-
n = 6
-
while True:
-
n -= 1
-
print "%-*s" % (10, alpha1*n) + "%*s" % (10, alpha1*n)
-
if n < 2:
-
break
-
m = 1
-
while True:
-
m += 1
-
print "%-*s" % (10, alpha1*m) + "%*s" % (10, alpha1*m)
-
if m > 4:
-
break
Output: - >>> aaaaa aaaaa
-
aaaa aaaa
-
aaa aaa
-
aa aa
-
a a
-
aa aa
-
aaa aaa
-
aaaa aaaa
-
aaaaa aaaaa
-
>>>
2 1517 bvdet 2,851
Expert Mod 2GB
You need only change two of the numbers. - alpha1 = 'a'
-
n = 6
-
while True:
-
n -= 1
-
print "%-*s" % (10, alpha1*n) + "%*s" % (10, alpha1*n)
-
if n < 2:
-
break
-
m = 1
-
while True:
-
m += 1
-
print "%-*s" % (10, alpha1*m) + "%*s" % (10, alpha1*m)
-
if m > 4:
-
break
Output: - >>> aaaaa aaaaa
-
aaaa aaaa
-
aaa aaa
-
aa aa
-
a a
-
aa aa
-
aaa aaa
-
aaaa aaaa
-
aaaaa aaaaa
-
>>>
bvdet 2,851
Expert Mod 2GB
Here's a version I like better: - letter = "a"
-
no_letters = 5
-
output = []
-
for i in range(no_letters, 1, -1):
-
output.append("%-*s%*s" % (10, letter*i, 10, letter*i))
-
for i in range(1, no_letters+1):
-
output.append("%-*s%*s" % (10, letter*i, 10, letter*i))
-
print "\n".join(output)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Krzysztof Pa¼ |
last post by:
Hi,
I want to make simple client in phyton, which would be able to communicate
with Java server using SSL sockets.
There is the Java clients, which is doing this - so I'm pretty sure, that
Java...
|
by: Hansan |
last post by:
Hi all, I hope you have time to help me out a little. My problem is that I
want to combine some python code I have made with some html templates, I
found a tutorial at dev shed:...
|
by: Grant Edwards |
last post by:
I've read over and over that Python leaves floating point
issues up to the underlying platform.
This seems to be largely true, but not always. My underlying
platform (IA32 Linux) correctly...
|
by: Paul Watson |
last post by:
It is clear that just using 'print' with variable names is relatively
uncontrollable. However, I thought that using a format string would
reign the problem in and give the desired output.
Must...
|
by: nojhan |
last post by:
I'm trying to embbed the python interpreter as a class attribute,
initializing it in the constructor, and finalizing in destructor.
The code is rather simple:
// base_path is an attribute of...
|
by: Wijaya Edward |
last post by:
Can we make loops control in Python?
What I mean is that whether we can control
which loops to exit/skip at the given scope.
For example in Perl we can do something like:
OUT:
foreach my $s1...
|
by: notejam |
last post by:
I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.
In basic language, I could write...
|
by: Jia Lu |
last post by:
Hi all
I'm trying to parsing html with re module.
html = """
<TABLE BORDER=1 cellspacing=0 cellpadding=2>
<TR>
<TH nowrap>DATA1</TH><TH nowrap>DATA2</HT><TH nowrap>DATA3</...
|
by: dominiquevalentine |
last post by:
Hello, I'm a teen trying to do my part in improving the world, and me
and my pal came up with some concepts to improve the transportation
system.
I have googled up and down for examples of using...
|
by: Dale |
last post by:
I am using a simple python webserver (see code below) to serve up
python scripts located in my cgi-bin directory.
import BaseHTTPServer
import CGIHTTPServer
class...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |