464,825 Members | 1,071 Online
Need help? Post your question and get tips & solutions from a community of 464,825 IT Pros & Developers. It's quick & easy.

# Combine output in python after break

 P: 4 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: Expand|Select|Wrap|Line Numbers 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: Expand|Select|Wrap|Line Numbers     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? Expand|Select|Wrap|Line Numbers     aaaaa          aaaaa     aaaa            aaaa     aaa              aaa     aa                aa     a                  a     aa                aa     aaa              aaa     aaaa            aaaa     aaaaa          aaaaa   Apr 22 '13 #1

You need only change two of the numbers.
Expand|Select|Wrap|Line Numbers
1. alpha1 = 'a'
2. n = 6
3. while True:
4.    n -= 1
5.    print "%-*s" % (10, alpha1*n) + "%*s" % (10, alpha1*n)
6.    if n < 2:
7.         break
8. m = 1
9. while True:
10.    m += 1
11.    print "%-*s" % (10, alpha1*m) + "%*s" % (10, alpha1*m)
12.    if m > 4:
13.         break
Output:
Expand|Select|Wrap|Line Numbers
1. >>> aaaaa          aaaaa
2. aaaa            aaaa
3. aaa              aaa
4. aa                aa
5. a                  a
6. aa                aa
7. aaa              aaa
8. aaaa            aaaa
9. aaaaa          aaaaa
10. >>>