Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the asterisk diamond in Python

Shulou Source: shulou.com Published: 2022-06-01 11:48:39 09月29日 Update

This article introduces the relevant knowledge of "how to achieve an asterisk diamond in Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. case of this section: asterisk diamond

The composition of the diamond:

1. Output the upper part of the diamond and get a triangle

2. Output the lower part of the diamond and get an opposite triangle.

3. The triangle in the lower part is one line less.

Second, the thinking process of the algorithm

Based on the output of each line, think about the following:

0 1 4 9

1 3 3 7

2 5 2 5

3 7 1 3

4 9 0 1

5 11

I 2*i+1 n//2-i-1 (n//2-i-1) * 2x1

III. Summary and emphasis

1. Procedural thinking training

2. Master the asterisk triangle

3. Master the algorithm of asterisk diamond

Knowledge source code:

The upper half of the triangle asterisk for i in range (nash end= 2: 1): # output space for j in range (nAccord 2 Meii): print (", end=") # output asterisk for j in range (2*i+1): print ("*") End= ") print () # lower half triangle asterisk for i in range (nCharachap2): # output space for j in range (item1): print (", end= ") # output asterisk for j in range (nhampach2)-iMuth1) * 2x1): print (" * ") End= "") print () "how does Python realize the asterisk diamond" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Asterisk output diamond triangle half knowledge line content idea more case space algorithm process part practical learned next dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi Shulou Technology Huawei OPPO Reno