Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the asterisk diamond in Python

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report