Nums Flashcards

1
Q

Num operations

A

Addition: 5 + 2
Subtraction: 5 - 2
Multiplication: 5 * 2
Exponentiation: 5 ** 2 ⇔ 5²
Division: 5 / 2 ⇒ 2.5
Floor Division: 5 // 2 ⇒ 2
Modulus: 5 % 2 ⇒ 1
a = 1
a+=1

a++ is not valid in python

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

Absolute value of a number

A

print(abs(-5)) # Output: 5

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

Adds all the elements of an iterable, like a list

A

print(sum([1, 2, 3])) # Output: 6

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

Raise a number to the power of another

A

pow(): Raises a number to the power of another.
pow(x, y) is equivalent to x**y. For example, pow(2, 3) would return 8.

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

Round a floating-point number to a specified number of decimal places

A

print(round(3.14159, 2)) # Output: 3.14

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

Return the smallest and largest values from an iterable

A

print(min([1, 2, 3])) # Output: 1
print(max([1, 2, 3])) # Output: 3

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

Calculate the square root of a number

A

import math
print(math.sqrt(9)) # Output: 3.0

You need to import the math module to use this function.

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

Calculates the factorial of a number.

A

import math
print(math.factorial(5)) # Output: 120

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

Compute logarithms in different bases

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