Programmer's way of thinking is from XX book (Python)

continue

Problem: Show sideways triangle > Using only two output statements, cout << "#" and cout << "\ n", Let's write a program to make a sideways triangle with a hash symbol (#)

Until the last problem, I used to use one liner, In my current situation, it doesn't fit or has been executed Since it was not organized, I wrote it in a file and executed it as follows. (Maybe the real answer is more nesting, I think I can write it well, Cannot m (_ _) m)

Answer below

test.py


#!/usr/bin/env python
#coding:utf-8

str = "####"
for i in range(1,5,1):
    slice = str[:i]
    print(slice)

for i in range(3,0,-1):
    slice = str[:i]
    print(slice)
・ ・ ・
$ python test.py
#
##
###
####
###
##
#

I feel very delicate.

Recommended Posts

Programmer's way of thinking is from XX book (Python)
Programmer's way of thinking is from XX book (Python)
From a book that makes the programmer's way of thinking interesting (Python)
From a book that programmers can learn ... (Python): Review of arrays
From a book that programmers can learn ... (Python): Pointer
I'm thinking of studying Python
From a book that programmers can learn ... (Python): About sorting
From a book that programmers can learn (Python): Decoding messages
Existence from the viewpoint of Python
From a book that programmers can learn (Python): Find the mode
Python3 compatible memo of "python start book"
From a book that programmers can learn (Python): Statistical processing-deviation value
What is the XX file at the root of a popular Python project?
From a book that programmers can learn (Python): Conditional search (maximum value)
What kind of book is the best-selling "Python Crash Course" in the world?
Learning notes from the beginning of Python 1
What kind of programming language is Python?
[python] [meta] Is the type of python a type?
Learning notes from the beginning of Python 2
From a book that programmers can learn: Verification of rune checksum (fixed length)
From a book that programmers can learn (Python): Class declaration (public / private, etc.)
Get the contents of git diff from python
The answer of "1/2" is different between python2 and 3
A memorandum of calling Python from Common Lisp
I tried Python! ] I graduated today from "What is Python! Python!"!
This is the only basic review of Python ~ 1 ~
This is the only basic review of Python ~ 2 ~
An easy way to call Java from Python
From a book that programmers can learn ... Verification of rune checksum (variable length) Part 2