Math Flashcards
What is the result of 5 / 2 in Python?
2.5 (decimal division)
What is the result of 5 // 2 in Python?
2 (// rounds to the smallest number)
What is the result of -3 // 2 in Python?
-2 (rounds to the smallest number)
What is the correct workaround for Python to round towards zero?
int(-3 / 2)
This will result in -1
When modding a value, what package can you use to get the correct negative value?
math.fmod()
What is the result of math.floor in Python?
Rounds down
What is the result of math.ceil in Python?
Rounds up
What package can you use in Python to get the square root of a number?
math.sqrt()
What package can you use to get the power of something in Python?
math.pow()
What is the best way to initialize a minimum possible value in Python?
float(“-inf”)
What is the best way to initialize a maximum possible value in Python?
float(“inf”)
True or False: You have to be careful when using float(“inf”) because Python values can overflow
False - Python values are infinite and never overflow