We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8aaddc1 commit 5eb45d4Copy full SHA for 5eb45d4
interview-cake/p37.py
@@ -0,0 +1,28 @@
1
+"""
2
+You have a function rand7() that generates a random integer from 1 to 7. Use it to write a function rand5() that
3
+generates a random integer from 1 to 5.
4
5
+import numpy as np
6
+def rand7():
7
+ return int(np.random.random()*7+1)
8
+
9
+def rand5():
10
+ result = 7
11
+ while result > 5:
12
+ result = rand7()
13
+ return result
14
15
+def rand5_v1():
16
+ stop = False
17
18
+ while stop == False:
19
+ num = rand7()
20
+ if num <= 5:
21
+ stop = True
22
+ return num
23
24
+# Test rand7():
25
26
+for i in range(10):
27
+ print(rand7())
28
0 commit comments