[Python] A program that creates stairs with #

[Python] A program that creates stairs with

This is a personal memo of hacker rank.

Make a # staircase with a given integer step.

n=In case of 6


     #
    ##
   ###
  ####
 #####
######

▼my answer

python


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


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

    staircase(n)

・ `String` * number Repeat the character string for the number

python


"#"*6

#output
'######'

python


"abc"*6

#output
'abcabcabcabcabcabc'

-Extracts the specified number of integers from 1.

range (n): Numbers from 0. → Add 1 to n.

python


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

#output
1
2
3

Recommended Posts

[Python] A program that creates stairs with #
[Python] A program that creates a two-dimensional array by combining integers
A typed world that begins with Python
A program that plays rock-paper-scissors using Python
[Python] A program that rounds the score
[Python / Tkinter] A class that creates a scrollable Frame
Create a page that loads infinitely with python
A program that removes duplicate statements in Python
Sample program that outputs syslog with Python logging
[Python] A program that counts the number of valleys
Try embedding Python in a C ++ program with pybind11
From buying a computer to running a program with python
Make a fortune with Python
A server that echoes data POSTed with flask / python
A program to write Lattice Hinge with Rhinoceros with Python
A memo that I touched the Datastore with python
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a directory with python
Using a Python program with fluentd's exec_filter Output Plugin
[Python] A program that compares the positions of kangaroos.
A Python program that converts ical data into text
Using a python program with fluentd's exec Output Plugin
A class that creates DB creation-data insertion with SQLite3 quickly
A Python program in "A book that gently teaches difficult programming"
A general-purpose program that formats Linux command strings in python
I wrote a program quickly to study DI with Python ①
Let's create a script that registers with Ideone.com in Python.
Use a macro that runs when saving python with vscode
I tried "a program that removes duplicate statements in Python"
[Python] A program that finds the most common bird types
A Python program that aggregates time usage from icalendar data
[Golang] A program that determines the turn with random numbers
[Python] What is a with statement?
Solve ABC163 A ~ C with Python
Operate a receipt printer with python
A python graphing manual with Matplotlib.
Let's make a GUI with python.
Solve ABC166 A ~ D with Python
Debug python multiprocess program with VSCode
Create a virtual environment with Python!
I made a fortune with Python.
Building a virtual environment with Python 3
Solve ABC168 A ~ C with Python
Make a recommender system with python
[Python] Generate a password with Slackbot
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Let's make a graph with python! !!
[Python] Inherit a class with class variables
I made a daemon with Python
Write a batch script with Python3.5 ~
When writing a program in Python
I made a program to collect images in tweets that I liked on twitter with Python
Let's create a program that automatically registers ID/PW from CSV to Bitwarden with Python + Selenium
A program that failed when trying to create a linebot with reference to "Dialogue system made with python"
How to batch start a python program created with Jupyter notebook
[Python] Make a graph that can be moved around with Plotly
I made a package that can compare morphological analyzers with Python
I want to use a wildcard that I want to shell with Python remove
[Python] A memo that I tried to get started with asyncio