Empire State Building Bet Flashcards

1
Q

Use seed() to set the seed; as an argument, pass 123. Then, generate your first random float with rand() and print it out.

A

np.random.seed(123)

print(np.random.rand())

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

how do i generate integers randomly?

A

randint()

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

Use randint() with the appropriate arguments to randomly generate the integer 1, 2, 3, 4, 5 or 6. This simulates a dice

A

print(np.random.randint(1, 7))

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

If step = 50, use if-elif-else statement, If dice is 1 or 2, you go one step down. If dice is 3, 4 or 5, you go one step up. Else, you throw the dice again. The number on the dice is the number of steps you go up.

A

if dice <= 2 :
step = step - 1
elif dice <= 5 :
step = step+1
else :
step = step + np.random.randint(1,7)

print(dice)
print(step)

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

What is a random walk?

A

Succession of random steps, like financial status of a gambler

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

Specify the beginning of a for loop so that the random walk is simulated five times.

A

for i in range(5) :

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

After a random_walk array is entirely populated, how do you append it to the all_walks list?

A

all_walks.append(random_walk)

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

Convert all_walks to NumPy array: np_aw

A

np_aw = np.array(all_walks)

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

Plot np_aw and show

A

plt.plot(np_aw)
plt.show()

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

Transpose np_aw: np_aw_t

A

np_aw_t = np.transpose(np_aw)

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

Finish the if condition so that step is set to 0 if a random float is less or equal to 0.005. Use np.random.rand():

if ___:
step = 0

A

if np.random.rand() <= 0.005 :
step = 0

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