Home > Article > Backend Development > Python training: calling the math library to perform mathematical operations
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!