Reputation: 11022
http://tekknolagi.co.cc/cgi-bin/helloworld.py
that's the output
what i would like it to do is make a pyramid shape
here's 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 do i get it to do that?
Upvotes: 3
Views: 329
Reputation: 6995
How's this?
#!/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
Upvotes: 2
Reputation: 118488
I had no clue about these justification functions.
A little ipython auto completion showed me a center
method.
for i in range(1, 10):
x = "hi " * i
print x.center(40)
Ya learn something every day.
Upvotes: 3
Reputation: 709
You can make use of the center
command so that you can print both sides at once:
for i in range(1, 10):
x = " hi" * i * 2
print x.center(80)
Upvotes: 4