Skip to content

Commit c9fea54

Browse files
author
Jessica Yung
committed
refactor(icake): refactor p37 rand5() from rand7()
1 parent 5eb45d4 commit c9fea54

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

interview-cake/p37.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
generates a random integer from 1 to 5.
44
"""
55
import numpy as np
6+
7+
68
def rand7():
79
return int(np.random.random()*7+1)
810

11+
912
def rand5():
1013
result = 7
1114
while result > 5:
1215
result = rand7()
1316
return result
1417

18+
1519
def rand5_v1():
1620
stop = False
1721

18-
while stop == False:
22+
while stop is False:
1923
num = rand7()
2024
if num <= 5:
21-
stop = True
2225
return num
2326

2427
# Test rand7():

interview-cake/p38.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
You have a function rand5() that generates a random integer from 1 to 5. Use it to write a function rand7() that
3+
generates a random integer from 1 to 7.
4+
5+
"""

0 commit comments

Comments
 (0)