In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the method of printing ninety-nine multiplication in different Python formats". In daily operation, I believe that many people have doubts about the method of printing ninety-nine multiplication in different Python formats. I have consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "what is the method of printing ninety-nine multiplication in different Python formats?" Next, please follow the editor to study!
The ninety-nine multiplication tables of output rectangle, upper left triangle, upper right triangle, lower left triangle and lower right triangle are realized by Python. The Python version I use is Python 3.2.2.
1. Complete rectangular format
Code:
# full format output 99 multiplication table 2 for i in range (1j10): 3 for j in range (1mag10): 4 print ("% d*%d=%2d"% (iLING j), end= ") 5 print (")
Output:
two。 Upper left triangle
Code:
# output in the upper left triangle format 99 multiplication table 2 for i in range (1mag10): 3 for j in range (iMag10): 4 print ("% d*%d=%2d"% (iGramage j), end= ") 5 print (")
Output:
Note: the multiplication formula is output by line, compared with the complete format, the inner loop range is iS9, when the I of the outer loop increases gradually, the number of formulas output per line will become less and less, print (") indicates a line break, if you do not output this sentence, the output multiplication table is out of order.
3. Upper right triangle
Code:
# output ninety-nine multiplication table for i in range (1p10): for k in range (1PowerI): print (end= "") for j in range (iPower10) in upper right triangle format: print ("% d*%d=%2d"% (end= ") print ("))
Output:
Note: compared with the upper left triangle, the inner loop statement has two more sentences (code red). Because each formula occupies a position of 7 bytes, it outputs the corresponding number of spaces beyond the previous space. In Python, the print ("") statement cannot be written directly to indicate the output space. The end keyword must be added to indicate that the end ends with the equal sign.
The content output of the edge is similar to the difference between the upper right and the upper left.
4. Lower left triangle
Code:
# output in lower left triangle format 99 multiplication Table 2 for i in range (1 for i in range 10): 3 for j in range (1 print 1): 4 print ("% d*%d=%2d"% (iLJ jJournal iMagj), end= ") 5 print (")
Output:
5. Lower right triangle
Code:
# output ninety-nine multiplication table for i in range (1j10) in lower right triangle format: for k in range (1mem10ripi): print (end= "") for j in range (1memire1): product=i*j print ("% d*%d=%2d"% (igraine jpen1 product), end= ") print (")
Output:
At this point, the study of "what is the method of printing ninety-nine multiplication in different Python formats" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.