Numbers Flashcards

1
Q

Infinity & negative infinity

A

x = float(‘inf’)

print(x) # inf
print(x > 10 ** 1000) # True

y = float(‘-inf’)

print(y) # -inf
print(y < -100000000) # True

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

Converting floats into fractions

A

x = 0.25

print(x.as_integer_ratio()) # (1, 4)

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

Rounding

A

1234.57

x = 1234.5678

print(round(x, 2))

x = 1234.5678

print(round(x, -2))

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

.divmod

A

quotient, remainder = divmod(57, 10)

print(quotient) # 5 (same as 57 // 10)
print(remainder) # 7 (same as 57 % 10)

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

Floating point inaccuracy

A

x = 5.000000000000000001
y = 5

print(x == 5) # True

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

Scientific notation

A

1500000.0

x = 1.5e6
print(x)

y = 6.4e-5
print(y)

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

NaN is a float

A

x = float(‘nan’)
print(x) # nan

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

Change base

A

x = int(‘10’, 2) # 2
x = int(‘11’, 2) # 3
x = int(‘100’, 2) # 4
x = int(‘101’, 2) # 5
x = int(‘110’, 2) # 6
x = int(‘111’, 2) # 7
x = int(‘1000’, 2) # 8

x = int(‘100’, 2) # 4

x = int(‘100’, 3) # 9

x = int(‘100’, 4) # 16

x = int(‘100’, 5) # 25

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