Math-related function usage
Import Math Module--import Math
1.floor () rounding down print (Math.flooor (6.1))
2.ceil () Up-Rounding print (Math.ceil (6.1))
3.round () rounding (odd if even, for system built-in functions) print (Round (5.8)) print (round (6.8))
4.pow () calculates a number of n-th-square print (Math.pow (5,3))
5.SQRT () Open square operation print (MATH.SQRT (9))
6.fabs () calculates the absolute value of a number and returns a floating-point type PRITN (Math.fabs (-6))
7,abs () calculates the absolute value, which is the system built-in function, which is the same as the original data type print (ABS (6))
8.MODF () splits a number into integers and decimals, returning a value of tuple print (MATH.MODF (5.5))
9.copysign () assigns the symbol of the second number to the first number print (Math.copysign (3,-3.5))
10.fsum () calculates the and (return value of floating-point) print (Math.fsum ([1,2,3,4,5,6]) of numbers in a sequence
11.sum () calculates the sum of numbers in a sequence (for the system built-in function, the return value is determined by the original value) print (SUM ([1,2,3,4,5,6]))
The values commonly used in 12.math modules
12.1 (PI) print (Math.PI)
12.2 E (natural logarithm) print (MATH.E)
#随机数模块
Import Random Number Module
Import Random
1.random () randomly gets the decimal between 0~1 (contains 0 does not contain 1)
Print (Random.random ())
2.choice () randomly returns a value from a sequence
Print (Random.choice ([1,2,3,4,5,6,7,8]))
3.shuffle () Random Shuffle list
Print (Random.shuffie ([1,2,3,4, ' A ', ' B '))
4.randrange () Gets the integer in the specified range
Print (Random.randrange (2,14,2))
5.uniform () Gets the random number of the specified range
Print (Random.uniform (2,14))
Python Learning--math-related module functions and the use of random number modules