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 :
operation result:
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!