Home > Backend Development > Python Tutorial > python method to print asterisk pyramid

python method to print asterisk pyramid

藏色散人
Release: 2020-05-11 09:01:02
Original
26895 people have browsed it

python method to print asterisk pyramid

Python method of printing asterisk pyramid

Use asterisks to output a pyramid (number of lines is customized)

Recommendation: "python tutorial"

Problem-solving ideas:

① Define a function to encapsulate, and the name can be chosen

② Calculate the number of spaces that need to be output in each line (the number of lines minus one)

③ Calculate the number of * signs that need to be output in each line (twice the number of lines minus one)

Knowledge supplement:

Function prototype: range (start, end, scan):

Parameter meaning: start: counting starts from start. The default is to start from 0. For example, range(5) is equivalent to range(0, 5)

end: counting to the end of end, but not including end. For example: range (0, 4) is [0, 1, 2, 3,] without 4

scan: The distance between each jump, the default is 1. For example: range (0, 5) is equivalent to range (0, 5, 1). The jump interval of range (0, 5, 2) is 2, and its value is "0 2 4"

Source code :

python method to print asterisk pyramid

operation result:

python method to print asterisk pyramid

The above is the detailed content of python method to print asterisk pyramid. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template