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 3 years have passed since last update.

【python】#で階段を作るプログラム

Posted at

#【python】#で階段を作るプログラム
hackerrankの自分用メモです。

与えられた整数の段を持つ#の階段を作る。

n=6の場合
     #
    ##
   ###
  ####
 #####
######

▼my answer

def staircase(n):
    for i in range(n):
        i += 1
        a = " "*(n-i)+"#"*i
        print(a)


if __name__ == '__main__':
    n = int(input())

    staircase(n)

・`文字列`*数値 数値分文字列を繰り返す
"#"*6

#出力
'######'
"abc"*6

#出力
'abcabcabcabcabcabc'

・指定した数だけ、1から整数を取り出す。

range(n):0からの数字になる。
 → nに1を足す。

n=3
for i in range(n):
   i += 1
   print(i)

#出力
1
2
3
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?