0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでコンソールにピラミッドを表示

Posted at

やること

コンソールに@だけでピラミッドを表示する

実行環境

-Ubuntu 18.04.2 LTS
-Python 3.6.8

表示結果

terminal
python pyramid.py 10
         @         
         @@         
        @@@@        
       @@@@@@       
      @@@@@@@@      
     @@@@@@@@@@

ソース

pyramid.py
import sys


args = sys.argv

num = int(args[1])

stone = '@'

space = ' '

i = 0

while i <= num:

    if i == 1:
        print(space * (num)  + (stone * i) + space * num)    
    print(space * (num)  + (stone * i * 2) + space * num)

    num -= 1
    i += 1

おわり

引数でピラミッドの最下段の石の数を指定します。

フォントサイズにもよりますが、私の環境ではデフォルトで105個まで最下段を増やせました。

一番上の石はどうしても左に寄ってしまいます。

アスタリスクやその他の記号でも表示できますが@が一番ピラミッドっぽく見えます。

大きなピラミッドを築きましょう。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?