Interval issue in python

http://tekknolagi.co.cc/cgi-bin/helloworld.py

that conclusion

what i would like to do is make a pyramid shape

here is the code ...

#! / usr / bin / env python
# - * - coding: UTF-8 - * -

# enable debugging
import cgitb
cgitb.enable ()

print "Content-Type: text / plain; charset = utf-8"
print



for i in range (1,10):
    x = "hi" * i
    print x.rjust (40)

for i in range (1, 10):
    x = "hi" * i
    print x.ljust (40)

How can i do this?

+3
source share
4 answers
print x.rjust(40) + x.ljust(40)
+4
source

You can use the command centerso that you can print both sides at the same time:

for i in range(1, 10):
    x = " hi" * i * 2
    print x.center(80)
+4
source

.

ipython center.

for i in range(1, 10):
    x = "hi " * i
    print x.center(40)

- .

+3

?

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"
print

for i in range(1,10):
    x = "hi "*i
    print x.rjust(40), x.ljust(40)
                                  hi  hi                                

                               hi hi  hi hi                             

                            hi hi hi  hi hi hi                          

                         hi hi hi hi  hi hi hi hi                       

                      hi hi hi hi hi  hi hi hi hi hi                    

                   hi hi hi hi hi hi  hi hi hi hi hi hi                 

                hi hi hi hi hi hi hi  hi hi hi hi hi hi hi              

             hi hi hi hi hi hi hi hi  hi hi hi hi hi hi hi hi           

          hi hi hi hi hi hi hi hi hi  hi hi hi hi hi hi hi hi hi
+2

Source: https://habr.com/ru/post/1788379/


All Articles