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

Python training: calling the math library to perform mathematical operations

little bottle
Release: 2019-04-27 16:17:04
Original
5071 people have browsed it

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()
Copy after login
数字        平方        几何级数      阶乘        
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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template