Home  >  Article  >  Backend Development  >  Python training: calling the math library to perform mathematical operations

Python training: calling the math library to perform mathematical operations

little bottle
little bottleOriginal
2019-04-27 16:17:044921browse

This article mainly talks about how Python calls the math library to implement mathematical operations and print them out. It has certain reference value and is very simple and easy to learn. Friends who are interested should come and learn about it.

Title: Print numbers from 1 to 10 as well as the square, geometric series and factorial of each number

from math import factorial

def main():
    print('%-10s%-10s%-10s%-10s' % ('数字', '平方', '几何级数', '阶乘'))
    for num in range(1, 11):
        print('%-12d%-12d%-12d%-12d' % (num, num ** 2, 2 ** num, factorial(num)))

if __name__ == '__main__':
    main()
数字        平方        几何级数      阶乘        
1           1           2           1           
2           4           4           2           
3           9           8           6           
4           16          16          24          
5           25          32          120         
6           36          64          720         
7           49          128         5040        
8           64          256         40320       
9           81          512         362880      
10          100         1024        3628800

Related tutorials: Python video tutorial

The above is the detailed content of Python training: calling the math library to perform mathematical operations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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