Python Math Flashcards

(19 cards)

1
Q

What is the operator for exponentiation (raising a number to a power) in Python?

A

**

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the built-in function to find the absolute value of a number?

A

abs()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What built-in function rounds a number to the nearest integer? (It rounds halves to the nearest even number in Python 3, but this can be complex to test for flashcards.)

A

round()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the operator for integer division (the result is the integer part of the quotient) in Python?

A

//

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the operator for the modulo operation (finding the remainder of a division) in Python?

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What Python math module function returns the square root of a number?

A

math.sqrt(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What Python math module function returns the value of $\pi$ (pi)?

A

math.pi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What Python math module function returns $e^x$ (e raised to the power of x)?

A

math.exp(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What Python math module function returns the natural logarithm of a number x (log base $e$)?

A

math.log(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What Python math module function returns the largest integer less than or equal to x (floor function)?

A

math.floor(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What Python math module function returns the smallest integer greater than or equal to x (ceiling function)?

A

math.ceil(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is required to use functions like sqrt or pi in Python?

A

import math (or from math import function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the definition of a prime number?

A

A natural number greater than 1 that has no positive divisors other than 1 and itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Are the numbers 0 and 1 considered prime?

A

No, they are not prime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the smallest prime number?

A
  1. It is the only even prime number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the basic logic to test if a number ‘n’ > 2 is prime?

A

Loop from 2 up to n-1 and check if ‘n’ is divisible by any number in that range.

17
Q

What operator checks if ‘n’ is perfectly divisible by ‘i’ in Python?

A

The modulo operator: n % i == 0

18
Q

What is the key optimization for a primality test loop for a number ‘n’?

A

You only need to check for divisors from 2 up to the square root of ‘n’.

19
Q

What Python ‘math’ module function helps implement the square root optimization?